diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 37e4c9a1378d1..c7de29d8bd0b4 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -465,6 +465,7 @@ Other Deprecations - Deprecated casting behavior when passing an item with mismatched-timezone to :meth:`DatetimeIndex.insert`, :meth:`DatetimeIndex.putmask`, :meth:`DatetimeIndex.where` :meth:`DatetimeIndex.fillna`, :meth:`Series.mask`, :meth:`Series.where`, :meth:`Series.fillna`, :meth:`Series.shift`, :meth:`Series.replace`, :meth:`Series.reindex` (and :class:`DataFrame` column analogues). In the past this has cast to object dtype. In a future version, these will cast the passed item to the index or series's timezone (:issue:`37605`) - Deprecated the 'errors' keyword argument in :meth:`Series.where`, :meth:`DataFrame.where`, :meth:`Series.mask`, and meth:`DataFrame.mask`; in a future version the argument will be removed (:issue:`44294`) - Deprecated :meth:`PeriodIndex.astype` to ``datetime64[ns]`` or ``DatetimeTZDtype``, use ``obj.to_timestamp(how).tz_localize(dtype.tz)`` instead (:issue:`44398`) +- Deprecated passing ``skipna=None`` for :meth:`DataFrame.mad` and :meth:`Series.mad`, pass ``skipna=True`` instead (:issue:`44580`) - Deprecated :meth:`DateOffset.apply`, use ``offset + other`` instead (:issue:`44522`) - A deprecation warning is now shown for :meth:`DataFrame.to_latex` indicating the arguments signature may change and emulate more the arguments to :meth:`.Styler.to_latex` in future versions (:issue:`44411`) - diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2215c39163b9a..2db8be19b4399 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10597,7 +10597,7 @@ def prod( product = prod - def mad(self, axis=None, skipna=None, level=None): + def mad(self, axis=None, skipna=True, level=None): """ {desc} @@ -10605,7 +10605,7 @@ def mad(self, axis=None, skipna=None, level=None): ---------- axis : {axis_descr} Axis for the function to be applied on. - skipna : bool, default None + skipna : bool, default True Exclude NA/null values when computing the result. level : int or level name, default None If the axis is a MultiIndex (hierarchical), count along a @@ -10617,7 +10617,14 @@ def mad(self, axis=None, skipna=None, level=None): {see_also}\ {examples} """ - if skipna is None: + if not is_bool(skipna): + warnings.warn( + "Passing None for skipna is deprecated and will raise in a future" + "version. Pass True instead. Only boolean values will be allowed " + "in the future.", + FutureWarning, + stacklevel=find_stack_level(), + ) skipna = True if axis is None: axis = self._stat_axis_number diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 8efae54dc7c11..0161acd8b52cf 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1478,6 +1478,12 @@ def test_frame_any_with_timedelta(self): expected = Series(data=[False, True]) tm.assert_series_equal(result, expected) + def test_reductions_deprecation_skipna_none(self, frame_or_series): + # GH#44580 + obj = frame_or_series([1, 2, 3]) + with tm.assert_produces_warning(FutureWarning, match="skipna"): + obj.mad(skipna=None) + def test_reductions_deprecation_level_argument( self, frame_or_series, reduction_functions ):