From 59bd617d91f6d70962a43fac898c14930bc28f60 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Wed, 15 Dec 2021 16:14:49 +0530 Subject: [PATCH 01/29] tighten return type in any --- pandas/core/generic.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 57f151feeae80..325593e7573ec 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10358,6 +10358,28 @@ def _logical_func( filter_type="bool", ) + @overload + def any( + self: DataFrame, + axis: Axis = ..., + bool_only: bool_t | None = ..., + skipna: bool_t = True, + level: Level | None = ..., + **kwargs, + ) -> Series: + ... + + @overload + def any( + self: Series, + axis: Axis = ..., + bool_only: bool_t | None = ..., + skipna: bool_t = True, + level: Level | None = ..., + **kwargs, + ) -> bool_t: + ... + def any( self, axis: Axis = 0, From 389cb03480956a4302f0d123611d29845568faaa Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Wed, 15 Dec 2021 17:14:56 +0530 Subject: [PATCH 02/29] correct overload definitions --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 325593e7573ec..7b3d7d8b189cf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10363,7 +10363,7 @@ def any( self: DataFrame, axis: Axis = ..., bool_only: bool_t | None = ..., - skipna: bool_t = True, + skipna: bool_t = ..., level: Level | None = ..., **kwargs, ) -> Series: @@ -10374,7 +10374,7 @@ def any( self: Series, axis: Axis = ..., bool_only: bool_t | None = ..., - skipna: bool_t = True, + skipna: bool_t = ..., level: Level | None = ..., **kwargs, ) -> bool_t: From 076efc0cc62e79cd63e4f02d0f1167ef3396753d Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Thu, 16 Dec 2021 00:02:52 +0530 Subject: [PATCH 03/29] add overload def for NDFrame input --- pandas/core/generic.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7b3d7d8b189cf..568fe1413c811 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10380,6 +10380,17 @@ def any( ) -> bool_t: ... + @overload + def any( + self: NDFrame, + axis: Axis = ..., + bool_only: bool_t | None = ..., + skipna: bool_t = ..., + level: Level | None = ..., + **kwargs, + ) -> Series | bool_t: + ... + def any( self, axis: Axis = 0, From 7f643d6207d0b726e782f0055ce813feaed631c3 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Thu, 16 Dec 2021 17:32:13 +0530 Subject: [PATCH 04/29] remove overload defs and define function any in sub-classes --- pandas/core/frame.py | 13 +++++++++++++ pandas/core/generic.py | 35 +---------------------------------- pandas/core/series.py | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fa5e9dc51419a..cac3346a692d1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8642,6 +8642,19 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate + @doc(NDFrame.any, **_shared_doc_kwargs) + def any( + self: DataFrame, + axis: Axis = 0, + bool_only: bool | None = None, + skipna: bool = True, + level: Level | None = None, + **kwargs, + ) -> Series: + return super().any( + axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs + ) + @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 568fe1413c811..a3a8c7bde0d80 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10358,39 +10358,6 @@ def _logical_func( filter_type="bool", ) - @overload - def any( - self: DataFrame, - axis: Axis = ..., - bool_only: bool_t | None = ..., - skipna: bool_t = ..., - level: Level | None = ..., - **kwargs, - ) -> Series: - ... - - @overload - def any( - self: Series, - axis: Axis = ..., - bool_only: bool_t | None = ..., - skipna: bool_t = ..., - level: Level | None = ..., - **kwargs, - ) -> bool_t: - ... - - @overload - def any( - self: NDFrame, - axis: Axis = ..., - bool_only: bool_t | None = ..., - skipna: bool_t = ..., - level: Level | None = ..., - **kwargs, - ) -> Series | bool_t: - ... - def any( self, axis: Axis = 0, @@ -10398,7 +10365,7 @@ def any( skipna: bool_t = True, level: Level | None = None, **kwargs, - ) -> Series | bool_t: + ): return self._logical_func( "any", nanops.nanany, axis, bool_only, skipna, level, **kwargs ) diff --git a/pandas/core/series.py b/pandas/core/series.py index 77bc816fd52a1..33a387ee13587 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -39,6 +39,7 @@ DtypeObj, FillnaOptions, IndexKeyFunc, + Level, SingleManager, StorageOptions, TimedeltaConvertibleTypes, @@ -4257,6 +4258,19 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate + @doc(NDFrame.any, **_shared_doc_kwargs) + def any( + self: Series, + axis: Axis = 0, + bool_only: bool | None = None, + skipna: bool = True, + level: Level | None = None, + **kwargs, + ) -> bool: + return super().any( + axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs + ) + @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], From d2653daea3a27ee0fc4eb8ce54e381134375fb6f Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Fri, 17 Dec 2021 12:52:10 +0530 Subject: [PATCH 05/29] add overload defs for level --- pandas/core/frame.py | 24 +++++++++++++++++++++++- pandas/core/series.py | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cac3346a692d1..59b271e10f653 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8642,6 +8642,28 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate + @overload + def any( + self: DataFrame, + axis: Axis = ..., + bool_only: bool | None = None, + skipna: bool = ..., + level: None = ..., + **kwargs, + ) -> Series: + ... + + @overload + def any( + self: DataFrame, + axis: Axis = ..., + bool_only: bool | None = None, + skipna: bool = ..., + level: Level = ..., + **kwargs, + ) -> DataFrame: + ... + @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: DataFrame, @@ -8650,7 +8672,7 @@ def any( skipna: bool = True, level: Level | None = None, **kwargs, - ) -> Series: + ) -> Series | DataFrame: return super().any( axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs ) diff --git a/pandas/core/series.py b/pandas/core/series.py index 33a387ee13587..0682a1dbcf0bb 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4258,6 +4258,28 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate + @overload + def any( + self: Series, + axis: Axis = ..., + bool_only: bool | None = None, + skipna: bool = ..., + level: None = ..., + **kwargs, + ) -> bool: + ... + + @overload + def any( + self: Series, + axis: Axis = ..., + bool_only: bool | None = None, + skipna: bool = ..., + level: Level = ..., + **kwargs, + ) -> Series: + ... + @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: Series, @@ -4266,7 +4288,7 @@ def any( skipna: bool = True, level: Level | None = None, **kwargs, - ) -> bool: + ) -> bool | Series: return super().any( axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs ) From 0f15b62996443a90b3ba177aa71ec93ccc84a068 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Fri, 17 Dec 2021 13:17:37 +0530 Subject: [PATCH 06/29] correct default val in overload defs --- pandas/core/frame.py | 4 ++-- pandas/core/series.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 59b271e10f653..3222ceb3d75b3 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8646,7 +8646,7 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): def any( self: DataFrame, axis: Axis = ..., - bool_only: bool | None = None, + bool_only: bool | None = ..., skipna: bool = ..., level: None = ..., **kwargs, @@ -8657,7 +8657,7 @@ def any( def any( self: DataFrame, axis: Axis = ..., - bool_only: bool | None = None, + bool_only: bool | None = ..., skipna: bool = ..., level: Level = ..., **kwargs, diff --git a/pandas/core/series.py b/pandas/core/series.py index 0682a1dbcf0bb..0920074a01b50 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4262,7 +4262,7 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): def any( self: Series, axis: Axis = ..., - bool_only: bool | None = None, + bool_only: bool | None = ..., skipna: bool = ..., level: None = ..., **kwargs, @@ -4273,7 +4273,7 @@ def any( def any( self: Series, axis: Axis = ..., - bool_only: bool | None = None, + bool_only: bool | None = ..., skipna: bool = ..., level: Level = ..., **kwargs, From 831481c5829847dffcb5ee6eb7bdb59da21aba5b Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Sat, 18 Dec 2021 15:38:07 +0530 Subject: [PATCH 07/29] deprecate non-keyword args --- pandas/core/frame.py | 23 +---------------------- pandas/core/series.py | 23 +---------------------- 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3222ceb3d75b3..e439b607d4d33 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8642,28 +8642,7 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate - @overload - def any( - self: DataFrame, - axis: Axis = ..., - bool_only: bool | None = ..., - skipna: bool = ..., - level: None = ..., - **kwargs, - ) -> Series: - ... - - @overload - def any( - self: DataFrame, - axis: Axis = ..., - bool_only: bool | None = ..., - skipna: bool = ..., - level: Level = ..., - **kwargs, - ) -> DataFrame: - ... - + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: DataFrame, diff --git a/pandas/core/series.py b/pandas/core/series.py index 0920074a01b50..0c060703401d8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4258,28 +4258,7 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate - @overload - def any( - self: Series, - axis: Axis = ..., - bool_only: bool | None = ..., - skipna: bool = ..., - level: None = ..., - **kwargs, - ) -> bool: - ... - - @overload - def any( - self: Series, - axis: Axis = ..., - bool_only: bool | None = ..., - skipna: bool = ..., - level: Level = ..., - **kwargs, - ) -> Series: - ... - + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: Series, From 284efd379e73aeab8ebe8d6fea31edc621ba5ec0 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Tue, 21 Dec 2021 23:11:34 +0530 Subject: [PATCH 08/29] add whatsnew note --- doc/source/whatsnew/v1.4.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 2b1182414ca2f..a11efb7c5d8a5 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -538,6 +538,7 @@ Other Deprecations - 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`) +- Deprecated passing arguments as positional in :meth:`DataFrame.any` and :meth:`Series.any` (:issue:`44802`) - .. --------------------------------------------------------------------------- From e002897cafa44e6108a195ff9f16acfeb308ab9d Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Tue, 21 Dec 2021 23:54:07 +0530 Subject: [PATCH 09/29] modify return types and add tests --- pandas/core/frame.py | 2 +- pandas/core/generic.py | 2 +- pandas/core/series.py | 2 +- pandas/tests/groupby/test_any_all.py | 26 ++++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e439b607d4d33..672d3a59882d1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8651,7 +8651,7 @@ def any( skipna: bool = True, level: Level | None = None, **kwargs, - ) -> Series | DataFrame: + ) -> DataFrame | Series: return super().any( axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs ) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a3a8c7bde0d80..c558eaa540588 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10365,7 +10365,7 @@ def any( skipna: bool_t = True, level: Level | None = None, **kwargs, - ): + ) -> DataFrame | Series | bool_t: return self._logical_func( "any", nanops.nanany, axis, bool_only, skipna, level, **kwargs ) diff --git a/pandas/core/series.py b/pandas/core/series.py index 0c060703401d8..d7687c2bfd531 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4267,7 +4267,7 @@ def any( skipna: bool = True, level: Level | None = None, **kwargs, - ) -> bool | Series: + ) -> Series | bool: return super().any( axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs ) diff --git a/pandas/tests/groupby/test_any_all.py b/pandas/tests/groupby/test_any_all.py index 13232d454a48c..ac5c35b8ba687 100644 --- a/pandas/tests/groupby/test_any_all.py +++ b/pandas/tests/groupby/test_any_all.py @@ -11,6 +11,10 @@ isna, ) import pandas._testing as tm +from pandas._testing.asserters import ( + assert_equal, + assert_series_equal, +) @pytest.mark.parametrize("agg_func", ["any", "all"]) @@ -61,6 +65,28 @@ def test_any(): tm.assert_frame_equal(result, expected) +def test_any_non_keyword_deprecation(): + df = DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]}) + msg = ( + "In a future version of pandas all arguments of " + "DataFrame.any will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + result = df.any("index") + expected = Series({"A": True, "B": True, "C": False}) + assert_series_equal(result, expected) + + s = Series([False, False, False]) + msg = ( + "In a future version of pandas all arguments of " + "Series.any will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + result = s.any("index") + expected = False + assert_equal(result, expected) + + @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) def test_bool_aggs_dup_column_labels(bool_agg_func): # 21668 From b229a3b2ea8024efdcc6653ce24906682aa11ff5 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Fri, 24 Dec 2021 15:59:17 +0530 Subject: [PATCH 10/29] move non-keyword deprecation to generic --- pandas/core/frame.py | 1 - pandas/core/generic.py | 5 +++++ pandas/core/series.py | 1 - pandas/tests/groupby/test_any_all.py | 6 +++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d903f6dfe48f5..d859b115291eb 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8636,7 +8636,6 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: DataFrame, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index dcb1b4e2f9746..f2f6a57ed3771 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -67,6 +67,7 @@ InvalidIndexError, ) from pandas.util._decorators import ( + deprecate_nonkeyword_arguments, doc, rewrite_axis_style_signature, ) @@ -10382,6 +10383,7 @@ def _logical_func( filter_type="bool", ) + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"], stacklevel=4) def any( self, axis: Axis = 0, @@ -10777,6 +10779,9 @@ def _add_numeric_operations(cls): """ axis_descr, name1, name2 = _doc_params(cls) + @deprecate_nonkeyword_arguments( + version=None, allowed_args=["self", "cond", "other"] + ) @doc( _bool_doc, desc=_any_desc, diff --git a/pandas/core/series.py b/pandas/core/series.py index d7687c2bfd531..c94b1f36c6529 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4258,7 +4258,6 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: Series, diff --git a/pandas/tests/groupby/test_any_all.py b/pandas/tests/groupby/test_any_all.py index ac5c35b8ba687..f2ed574f2964a 100644 --- a/pandas/tests/groupby/test_any_all.py +++ b/pandas/tests/groupby/test_any_all.py @@ -69,17 +69,17 @@ def test_any_non_keyword_deprecation(): df = DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]}) msg = ( "In a future version of pandas all arguments of " - "DataFrame.any will be keyword-only" + "NDFrame.any will be keyword-only." ) with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.any("index") + result = df.any("index", None) expected = Series({"A": True, "B": True, "C": False}) assert_series_equal(result, expected) s = Series([False, False, False]) msg = ( "In a future version of pandas all arguments of " - "Series.any will be keyword-only" + "NDFrame.any will be keyword-only." ) with tm.assert_produces_warning(FutureWarning, match=msg): result = s.any("index") From 0c3ebd76c0676e6a21529c1282488b8b31b5350f Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Fri, 24 Dec 2021 16:06:44 +0530 Subject: [PATCH 11/29] correct deprecation decorators --- pandas/core/frame.py | 1 + pandas/core/generic.py | 5 ----- pandas/core/series.py | 1 + pandas/tests/groupby/test_any_all.py | 4 ++-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d859b115291eb..d903f6dfe48f5 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8636,6 +8636,7 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: DataFrame, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f2f6a57ed3771..dcb1b4e2f9746 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -67,7 +67,6 @@ InvalidIndexError, ) from pandas.util._decorators import ( - deprecate_nonkeyword_arguments, doc, rewrite_axis_style_signature, ) @@ -10383,7 +10382,6 @@ def _logical_func( filter_type="bool", ) - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"], stacklevel=4) def any( self, axis: Axis = 0, @@ -10779,9 +10777,6 @@ def _add_numeric_operations(cls): """ axis_descr, name1, name2 = _doc_params(cls) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "cond", "other"] - ) @doc( _bool_doc, desc=_any_desc, diff --git a/pandas/core/series.py b/pandas/core/series.py index c94b1f36c6529..d7687c2bfd531 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4258,6 +4258,7 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: Series, diff --git a/pandas/tests/groupby/test_any_all.py b/pandas/tests/groupby/test_any_all.py index f2ed574f2964a..2a2ba3ebf92ea 100644 --- a/pandas/tests/groupby/test_any_all.py +++ b/pandas/tests/groupby/test_any_all.py @@ -69,7 +69,7 @@ def test_any_non_keyword_deprecation(): df = DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]}) msg = ( "In a future version of pandas all arguments of " - "NDFrame.any will be keyword-only." + "DataFrame.any will be keyword-only." ) with tm.assert_produces_warning(FutureWarning, match=msg): result = df.any("index", None) @@ -79,7 +79,7 @@ def test_any_non_keyword_deprecation(): s = Series([False, False, False]) msg = ( "In a future version of pandas all arguments of " - "NDFrame.any will be keyword-only." + "Series.any will be keyword-only." ) with tm.assert_produces_warning(FutureWarning, match=msg): result = s.any("index") From cdb96f7b7f0091d697964ef5ab9a7dacfa423b43 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Fri, 1 Apr 2022 06:48:48 +0530 Subject: [PATCH 12/29] remove imports in test assertions --- pandas/tests/groupby/test_any_all.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/tests/groupby/test_any_all.py b/pandas/tests/groupby/test_any_all.py index 902a9f2ca5b61..f3bb9637e8a77 100644 --- a/pandas/tests/groupby/test_any_all.py +++ b/pandas/tests/groupby/test_any_all.py @@ -11,10 +11,6 @@ isna, ) import pandas._testing as tm -from pandas._testing.asserters import ( - assert_equal, - assert_series_equal, -) @pytest.mark.parametrize("agg_func", ["any", "all"]) @@ -74,7 +70,7 @@ def test_any_non_keyword_deprecation(): with tm.assert_produces_warning(FutureWarning, match=msg): result = df.any("index", None) expected = Series({"A": True, "B": True, "C": False}) - assert_series_equal(result, expected) + tm.assert_series_equal(result, expected) s = Series([False, False, False]) msg = ( @@ -84,7 +80,7 @@ def test_any_non_keyword_deprecation(): with tm.assert_produces_warning(FutureWarning, match=msg): result = s.any("index") expected = False - assert_equal(result, expected) + tm.assert_equal(result, expected) @pytest.mark.parametrize("bool_agg_func", ["any", "all"]) From 76003ed0061e89ac8784cc9260edad571e45a6f8 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Mon, 4 Apr 2022 18:25:31 +0530 Subject: [PATCH 13/29] place deprecate_nonkeyword at correct place --- pandas/core/frame.py | 1 - pandas/core/generic.py | 1 + pandas/core/series.py | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b099a42a529df..29d7102535176 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8897,7 +8897,6 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: DataFrame, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index abeffc3a4aacc..8474f68b54377 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10619,6 +10619,7 @@ def _logical_func( filter_type="bool", ) + @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) def any( self, axis: Axis = 0, diff --git a/pandas/core/series.py b/pandas/core/series.py index f02d3af89552d..8b57e6905b7f3 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4396,7 +4396,6 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(NDFrame.any, **_shared_doc_kwargs) def any( self: Series, From 787616d5c905f1eacb58ff0b90d181b36c772701 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Mon, 4 Apr 2022 18:57:50 +0530 Subject: [PATCH 14/29] remove changes from frame.py, series.py --- pandas/core/frame.py | 13 ------------- pandas/core/series.py | 13 ------------- pandas/tests/groupby/test_any_all.py | 4 ++-- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 29d7102535176..d56e4ef451954 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8897,19 +8897,6 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate - @doc(NDFrame.any, **_shared_doc_kwargs) - def any( - self: DataFrame, - axis: Axis = 0, - bool_only: bool | None = None, - skipna: bool = True, - level: Level | None = None, - **kwargs, - ) -> DataFrame | Series: - return super().any( - axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs - ) - @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], diff --git a/pandas/core/series.py b/pandas/core/series.py index 8b57e6905b7f3..83c5e8206952c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4396,19 +4396,6 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate - @doc(NDFrame.any, **_shared_doc_kwargs) - def any( - self: Series, - axis: Axis = 0, - bool_only: bool | None = None, - skipna: bool = True, - level: Level | None = None, - **kwargs, - ) -> Series | bool: - return super().any( - axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs - ) - @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], diff --git a/pandas/tests/groupby/test_any_all.py b/pandas/tests/groupby/test_any_all.py index f3bb9637e8a77..fa17ba0e3dca8 100644 --- a/pandas/tests/groupby/test_any_all.py +++ b/pandas/tests/groupby/test_any_all.py @@ -65,7 +65,7 @@ def test_any_non_keyword_deprecation(): df = DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]}) msg = ( "In a future version of pandas all arguments of " - "DataFrame.any will be keyword-only." + "NDFrame.any will be keyword-only." ) with tm.assert_produces_warning(FutureWarning, match=msg): result = df.any("index", None) @@ -75,7 +75,7 @@ def test_any_non_keyword_deprecation(): s = Series([False, False, False]) msg = ( "In a future version of pandas all arguments of " - "Series.any will be keyword-only." + "NDFrame.any will be keyword-only." ) with tm.assert_produces_warning(FutureWarning, match=msg): result = s.any("index") From 03753477367b38803e8d5e0c1c0f3e6210deb986 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Mon, 4 Apr 2022 19:13:43 +0530 Subject: [PATCH 15/29] readd changes in frame, series without actual implementations --- pandas/core/frame.py | 11 +++++++++++ pandas/core/series.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d56e4ef451954..16d451a6c9fd2 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8897,6 +8897,17 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate + @doc(NDFrame.any, **_shared_doc_kwargs) + def any( + self: DataFrame, + axis: Axis = 0, + bool_only: bool | None = None, + skipna: bool = True, + level: Level | None = None, + **kwargs, + ) -> DataFrame | Series: + ... + @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], diff --git a/pandas/core/series.py b/pandas/core/series.py index 83c5e8206952c..95784200e2405 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4396,6 +4396,17 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate + @doc(NDFrame.any, **_shared_doc_kwargs) + def any( + self: Series, + axis: Axis = 0, + bool_only: bool | None = None, + skipna: bool = True, + level: Level | None = None, + **kwargs, + ) -> Series | bool: + ... + @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], From a13ee6faa9665e8102302e32188b09abca8baf32 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Mon, 4 Apr 2022 20:20:53 +0530 Subject: [PATCH 16/29] place deprecate_nonkeyword at other place --- pandas/core/generic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8be59ab85b89f..022df79a520a5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10510,7 +10510,6 @@ def _logical_func( filter_type="bool", ) - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) def any( self, axis: Axis = 0, @@ -10933,6 +10932,9 @@ def _add_numeric_operations(cls): """ axis_descr, name1, name2 = _doc_params(cls) + @deprecate_nonkeyword_arguments( + version=None, allowed_args=["self"], stacklevel=2 + ) @doc( _bool_doc, desc=_any_desc, From 6e5b3aca33ab10db831dfc54149c890b11aa7d2a Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Mon, 4 Apr 2022 21:08:06 +0530 Subject: [PATCH 17/29] add name argument to deprecate_non_keyword_args decorator --- pandas/core/generic.py | 5 ++++- pandas/tests/groupby/test_any_all.py | 4 ++-- pandas/util/_decorators.py | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 022df79a520a5..2d52c79bb2687 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10933,7 +10933,10 @@ def _add_numeric_operations(cls): axis_descr, name1, name2 = _doc_params(cls) @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self"], stacklevel=2 + version=None, + allowed_args=["self"], + stacklevel=2, + name="DataFrame.any and Series.any", ) @doc( _bool_doc, diff --git a/pandas/tests/groupby/test_any_all.py b/pandas/tests/groupby/test_any_all.py index fa17ba0e3dca8..784ff1069e7ff 100644 --- a/pandas/tests/groupby/test_any_all.py +++ b/pandas/tests/groupby/test_any_all.py @@ -65,7 +65,7 @@ def test_any_non_keyword_deprecation(): df = DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]}) msg = ( "In a future version of pandas all arguments of " - "NDFrame.any will be keyword-only." + "DataFrame.any and Series.any will be keyword-only." ) with tm.assert_produces_warning(FutureWarning, match=msg): result = df.any("index", None) @@ -75,7 +75,7 @@ def test_any_non_keyword_deprecation(): s = Series([False, False, False]) msg = ( "In a future version of pandas all arguments of " - "NDFrame.any will be keyword-only." + "DataFrame.any and Series.any will be keyword-only." ) with tm.assert_produces_warning(FutureWarning, match=msg): result = s.any("index") diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 2b160d2946b2b..ce82297222d13 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -261,6 +261,7 @@ def deprecate_nonkeyword_arguments( version: str | None, allowed_args: list[str] | None = None, stacklevel: int = 2, + name: str | None = None, ) -> Callable[[F], F]: """ Decorator to deprecate a use of non-keyword arguments of a function. @@ -294,9 +295,12 @@ def decorate(func): allow_args = spec.args[: -len(spec.defaults)] num_allow_args = len(allow_args) + nonlocal name + if name is None: + name = func.__qualname__ msg = ( f"{future_version_msg(version)} all arguments of " - f"{func.__qualname__}{{arguments}} will be keyword-only." + f"{name}{{arguments}} will be keyword-only." ) @wraps(func) From 63ae9c18b13ca72a99b6926fb3c4392f21e198c3 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Mon, 4 Apr 2022 23:08:57 +0530 Subject: [PATCH 18/29] add test for name in deprecate_nonkeyword_args --- pandas/core/generic.py | 2 +- .../util/test_deprecate_nonkeyword_arguments.py | 17 ++++++++++++++++- pandas/util/_decorators.py | 5 +---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2d52c79bb2687..060b582278652 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1976,7 +1976,7 @@ def __array_wrap__( "The __array_wrap__ method of DataFrame and Series will be removed in " "a future version", DeprecationWarning, - stacklevel=2, + stacklevel=find_stack_level(), ) res = lib.item_from_zerodim(result) if is_scalar(res): diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index c03639811d9d5..346561e0ba7ff 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -9,7 +9,9 @@ import pandas._testing as tm -@deprecate_nonkeyword_arguments(version="1.1", allowed_args=["a", "b"]) +@deprecate_nonkeyword_arguments( + version="1.1", allowed_args=["a", "b"], name="f_add_inputs" +) def f(a, b=0, c=0, d=0): return a + b + c + d @@ -44,6 +46,19 @@ def test_four_arguments(): assert f(1, 2, 3, 4) == 10 +def test_three_arguments_with_name_in_warning(): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + assert f(6, 3, 3) == 12 + assert len(w) == 1 + for actual_warning in w: + assert actual_warning.category == FutureWarning + assert str(actual_warning.message) == ( + "Starting with pandas version 1.1 all arguments of f_add_inputs " + "except for the arguments 'a' and 'b' will be keyword-only." + ) + + @deprecate_nonkeyword_arguments(version="1.1") def g(a, b=0, c=0, d=0): with tm.assert_produces_warning(None): diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index ce82297222d13..f1bbeade6b887 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -295,12 +295,9 @@ def decorate(func): allow_args = spec.args[: -len(spec.defaults)] num_allow_args = len(allow_args) - nonlocal name - if name is None: - name = func.__qualname__ msg = ( f"{future_version_msg(version)} all arguments of " - f"{name}{{arguments}} will be keyword-only." + f"{name or func.__qualname__}{{arguments}} will be keyword-only." ) @wraps(func) From 1010e1e106c6a207fde5bb2cd9a54e9319680c4f Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Mon, 4 Apr 2022 23:14:18 +0530 Subject: [PATCH 19/29] remove changes from frame.py, series.py --- pandas/core/frame.py | 11 ----------- pandas/core/series.py | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 618c9a36eb3f5..6d4deb79b4898 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8942,17 +8942,6 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate - @doc(NDFrame.any, **_shared_doc_kwargs) - def any( - self: DataFrame, - axis: Axis = 0, - bool_only: bool | None = None, - skipna: bool = True, - level: Level | None = None, - **kwargs, - ) -> DataFrame | Series: - ... - @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], diff --git a/pandas/core/series.py b/pandas/core/series.py index 1cc15d1c2c636..1d3509cac0edd 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4397,17 +4397,6 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): agg = aggregate - @doc(NDFrame.any, **_shared_doc_kwargs) - def any( - self: Series, - axis: Axis = 0, - bool_only: bool | None = None, - skipna: bool = True, - level: Level | None = None, - **kwargs, - ) -> Series | bool: - ... - @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], From 424b213c15a6f7ba95a406706db607c8690f4787 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Mon, 4 Apr 2022 23:18:19 +0530 Subject: [PATCH 20/29] correct stacklevel in warning --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 060b582278652..2cb8751758f22 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1976,7 +1976,7 @@ def __array_wrap__( "The __array_wrap__ method of DataFrame and Series will be removed in " "a future version", DeprecationWarning, - stacklevel=find_stack_level(), + stacklevel=2, ) res = lib.item_from_zerodim(result) if is_scalar(res): @@ -10935,7 +10935,7 @@ def _add_numeric_operations(cls): @deprecate_nonkeyword_arguments( version=None, allowed_args=["self"], - stacklevel=2, + stacklevel=find_stack_level(), name="DataFrame.any and Series.any", ) @doc( From 8007cf154f891f6da1b26408cc448dd485341bf3 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Mon, 4 Apr 2022 19:34:32 +0100 Subject: [PATCH 21/29] correct stacklevel --- 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 2cb8751758f22..711991e306953 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10935,7 +10935,7 @@ def _add_numeric_operations(cls): @deprecate_nonkeyword_arguments( version=None, allowed_args=["self"], - stacklevel=find_stack_level(), + stacklevel=find_stack_level() - 1, name="DataFrame.any and Series.any", ) @doc( From a36163751462751c42eb5a72f4770f2ed82f42c5 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Tue, 5 Apr 2022 00:07:35 +0530 Subject: [PATCH 22/29] set stacklevel to default --- pandas/core/generic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2cb8751758f22..9e778cd6a4317 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10935,7 +10935,6 @@ def _add_numeric_operations(cls): @deprecate_nonkeyword_arguments( version=None, allowed_args=["self"], - stacklevel=find_stack_level(), name="DataFrame.any and Series.any", ) @doc( From 2678298c348a5c708dc11f112d5b5b225563e53c Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Tue, 5 Apr 2022 14:39:51 +0530 Subject: [PATCH 23/29] move deprecation message to whatsnew v1.5.0.rst --- doc/source/whatsnew/v1.4.0.rst | 1 - doc/source/whatsnew/v1.5.0.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 9339642a693fb..87982a149054c 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -722,7 +722,6 @@ Other Deprecations - Deprecated :meth:`DateOffset.apply`, use ``offset + other`` instead (:issue:`44522`) - Deprecated parameter ``names`` in :meth:`Index.copy` (:issue:`44916`) - 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`) -- Deprecated passing arguments as positional in :meth:`DataFrame.any` and :meth:`Series.any` (:issue:`44802`) - Deprecated behavior of :func:`concat` between objects with bool-dtype and numeric-dtypes; in a future version these will cast to object dtype instead of coercing bools to numeric values (:issue:`39817`) - Deprecated :meth:`Categorical.replace`, use :meth:`Series.replace` instead (:issue:`44929`) - Deprecated passing ``set`` or ``dict`` as indexer for :meth:`DataFrame.loc.__setitem__`, :meth:`DataFrame.loc.__getitem__`, :meth:`Series.loc.__setitem__`, :meth:`Series.loc.__getitem__`, :meth:`DataFrame.__getitem__`, :meth:`Series.__getitem__` and :meth:`Series.__setitem__` (:issue:`42825`) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 56b1a6317472b..3cf2edb7bc79a 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -426,6 +426,7 @@ Other Deprecations - Deprecated behavior of method :meth:`DataFrame.quantile`, attribute ``numeric_only`` will default False. Including datetime/timedelta columns in the result (:issue:`7308`). - Deprecated :attr:`Timedelta.freq` and :attr:`Timedelta.is_populated` (:issue:`46430`) - Deprecated :attr:`Timedelta.delta` (:issue:`46476`) +- Deprecated passing arguments as positional in :meth:`DataFrame.any` and :meth:`Series.any` (:issue:`44802`) - .. --------------------------------------------------------------------------- From 96de045b4fcfec458915c5187be5ace02feb21ad Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Tue, 5 Apr 2022 14:48:17 +0530 Subject: [PATCH 24/29] add name parameter in deprecate_non_keyword_args docstring --- pandas/util/_decorators.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index f1bbeade6b887..10954cb2fa74d 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -282,6 +282,11 @@ def deprecate_nonkeyword_arguments( stacklevel : int, default=2 The stack level for warnings.warn + + name: str, optional + The specific name of the function to show in the warning + message. If None, then the Qualified name of the function + is used. """ def decorate(func): From 86ad6badefbc460c014ec26bc9659f89ffcd0459 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Tue, 5 Apr 2022 14:52:42 +0530 Subject: [PATCH 25/29] correct whitespace in deprecate_nonkeyword_args docstring --- pandas/util/_decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 10954cb2fa74d..6f8889e9017d0 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -283,7 +283,7 @@ def deprecate_nonkeyword_arguments( stacklevel : int, default=2 The stack level for warnings.warn - name: str, optional + name : str, optional The specific name of the function to show in the warning message. If None, then the Qualified name of the function is used. From b4b3a1f6202a3f5c2db1b9cbd3df6a968f3e7892 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Thu, 7 Apr 2022 18:54:45 +0530 Subject: [PATCH 26/29] update any non-keyword args in other tests --- pandas/tests/frame/test_reductions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index cc0195bf1dff9..fc3e4dcd1bfe5 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1055,11 +1055,11 @@ def test_any_all_extra(self): }, index=["a", "b", "c"], ) - result = df[["A", "B"]].any(1) + result = df[["A", "B"]].any(axis=1) expected = Series([True, True, False], index=["a", "b", "c"]) tm.assert_series_equal(result, expected) - result = df[["A", "B"]].any(1, bool_only=True) + result = df[["A", "B"]].any(axis=1, bool_only=True) tm.assert_series_equal(result, expected) result = df.all(1) @@ -1108,7 +1108,7 @@ def test_any_datetime(self): ] df = DataFrame({"A": float_data, "B": datetime_data}) - result = df.any(1) + result = df.any(axis=1) expected = Series([True, True, True, False]) tm.assert_series_equal(result, expected) From 11917aaf3b538762e1a3ba133a341551f20c2690 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Thu, 7 Apr 2022 19:05:05 +0530 Subject: [PATCH 27/29] update any in doc --- doc/source/whatsnew/v0.13.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.13.0.rst b/doc/source/whatsnew/v0.13.0.rst index b2596358d0c9d..8265ad58f7ea3 100644 --- a/doc/source/whatsnew/v0.13.0.rst +++ b/doc/source/whatsnew/v0.13.0.rst @@ -664,7 +664,7 @@ Enhancements other = pd.DataFrame({'A': [1, 3, 3, 7], 'B': ['e', 'f', 'f', 'e']}) mask = dfi.isin(other) mask - dfi[mask.any(1)] + dfi[mask.any(axis=1)] - ``Series`` now supports a ``to_frame`` method to convert it to a single-column DataFrame (:issue:`5164`) From 35c71b6112a8d020a8786e2bc63ed783f5d15661 Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Fri, 8 Apr 2022 00:55:14 +0530 Subject: [PATCH 28/29] update remaining any() calls in pandas/core --- pandas/core/generic.py | 2 +- pandas/core/missing.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 711991e306953..63ee6f0c799bf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7224,7 +7224,7 @@ def asof(self, where, subset=None): if not isinstance(where, Index): where = Index(where) if is_list else Index([where]) - nulls = self.isna() if is_series else self[subset].isna().any(1) + nulls = self.isna() if is_series else self[subset].isna().any(axis=1) if nulls.all(): if is_series: self = cast("Series", self) diff --git a/pandas/core/missing.py b/pandas/core/missing.py index 46ea23e431d15..b0bfbf13fbb2c 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -191,7 +191,7 @@ def find_valid_index(values, *, how: str) -> int | None: is_valid = ~isna(values) if values.ndim == 2: - is_valid = is_valid.any(1) # reduce axis 1 + is_valid = is_valid.any(axis=1) # reduce axis 1 if how == "first": idxpos = is_valid[::].argmax() From 0e6d5eb123fbe340a2dc0713e45fb15cb620fbbd Mon Sep 17 00:00:00 2001 From: yadav-sachin Date: Fri, 8 Apr 2022 14:48:27 +0530 Subject: [PATCH 29/29] correct docstring of isocalendar in pandas/core/indexes/accessors.py --- pandas/core/indexes/accessors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index a0bc0ae8e3511..f9a817d3856bb 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -243,7 +243,7 @@ def freq(self): def isocalendar(self): """ - Returns a DataFrame with the year, week, and day calculated according to + Return a DataFrame with the year, week, and day calculated according to the ISO 8601 standard. .. versionadded:: 1.1.0 @@ -251,7 +251,7 @@ def isocalendar(self): Returns ------- DataFrame - with columns year, week and day + With columns year, week and day. See Also --------