From a62f01d08944e0fc8f9d469468fdc3beeee78635 Mon Sep 17 00:00:00 2001 From: phofl Date: Mon, 22 Nov 2021 22:37:15 +0100 Subject: [PATCH 1/4] Deprecate skipna=None for mad --- doc/source/whatsnew/v1.4.0.rst | 1 + pandas/core/generic.py | 13 ++++++++++--- pandas/tests/frame/test_reductions.py | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 1f656f267783f..ba3b83311fc09 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -464,6 +464,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`) - diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 888376ea8e1dc..1fd1e29da6a8a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10579,7 +10579,7 @@ def prod( product = prod - def mad(self, axis=None, skipna=None, level=None): + def mad(self, axis=None, skipna=True, level=None): """ {desc} @@ -10587,7 +10587,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 @@ -10600,6 +10600,13 @@ def mad(self, axis=None, skipna=None, level=None): {examples} """ if skipna is None: + 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 @@ -10669,7 +10676,7 @@ def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): see_also="", examples="", ) - def mad(self, axis=None, skipna=None, level=None): + def mad(self, axis=None, skipna=True, level=None): return NDFrame.mad(self, axis, skipna, level) setattr(cls, "mad", mad) diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index fc2c138538ac9..902832294c8f8 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) + @pytest.mark.parametrize( "func", [ From a659bc21403f4685dbfcad070acf256be41acbf0 Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 23 Nov 2021 10:02:59 +0100 Subject: [PATCH 2/4] Check for bool dtype --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1fd1e29da6a8a..64e90b5fb1857 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10599,7 +10599,7 @@ def mad(self, axis=None, skipna=True, level=None): {see_also}\ {examples} """ - if skipna is None: + if not is_bool_dtype(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 " From bd2c4f7b586c1ea57406d18660bd67690bfc8ade Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 23 Nov 2021 10:45:28 +0100 Subject: [PATCH 3/4] Check for instance --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 64e90b5fb1857..f8244e074131d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10599,7 +10599,7 @@ def mad(self, axis=None, skipna=True, level=None): {see_also}\ {examples} """ - if not is_bool_dtype(skipna): + if not isinstance(skipna, bool): warnings.warn( "Passing None for skipna is deprecated and will raise in a future" "version. Pass True instead. Only boolean values will be allowed " From 56b6d49c8679aa00447fdb31325f561474db7557 Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 23 Nov 2021 21:30:28 +0100 Subject: [PATCH 4/4] Change check --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f8244e074131d..e7fae809e50c6 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10599,7 +10599,7 @@ def mad(self, axis=None, skipna=True, level=None): {see_also}\ {examples} """ - if not isinstance(skipna, bool): + 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 "