From 22f34086ec28eff9f9e736b52cfa9e185fd8af32 Mon Sep 17 00:00:00 2001 From: pedrocariellof Date: Wed, 15 May 2024 01:03:29 -0300 Subject: [PATCH 1/9] Deprecation of groupby.corrwith --- doc/source/development/policies.rst | 2 ++ doc/source/getting_started/install.rst | 2 +- doc/source/whatsnew/v3.0.0.rst | 2 ++ pandas/core/groupby/generic.py | 7 +++++ pandas/tests/groupby/test_all_methods.py | 23 ++++++++++---- pandas/tests/groupby/test_apply.py | 9 +++++- pandas/tests/groupby/test_categorical.py | 30 +++++++++++++++---- pandas/tests/groupby/test_groupby_dropna.py | 20 +++++++++++-- pandas/tests/groupby/test_numeric_only.py | 18 +++++++++-- pandas/tests/groupby/test_raises.py | 8 +++++ .../tests/groupby/transform/test_transform.py | 20 +++++++++++-- 11 files changed, 121 insertions(+), 20 deletions(-) diff --git a/doc/source/development/policies.rst b/doc/source/development/policies.rst index 8465820452353..f958e4c4ad1fc 100644 --- a/doc/source/development/policies.rst +++ b/doc/source/development/policies.rst @@ -46,6 +46,8 @@ deprecation removed in the next major release (2.0.0). These policies do not apply to features marked as **experimental** in the documentation. pandas may change the behavior of experimental features at any time. +.. _policies.python_support: + Python support ~~~~~~~~~~~~~~ diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index cf5f15ceb8344..01a79fc8e36fd 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -21,7 +21,7 @@ Instructions for installing :ref:`from source `, Python version support ---------------------- -Officially Python 3.9, 3.10, 3.11 and 3.12. +See :ref:`Python support policy `. Installing pandas ----------------- diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 083e004fb94fa..a8d46dd9125a2 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -171,6 +171,8 @@ Other API changes Deprecations ~~~~~~~~~~~~ +- Deprecated :meth:`Groupby.corrwith` (:issue:`57158`) + Copy keyword ^^^^^^^^^^^^ diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 0a048d11d0b4d..83793df7c601c 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -23,10 +23,12 @@ ) import numpy as np +import warnings from pandas._libs import Interval from pandas._libs.hashtable import duplicated from pandas.errors import SpecificationError +from pandas.util._exceptions import find_stack_level from pandas.util._decorators import ( Appender, Substitution, @@ -2785,6 +2787,11 @@ def corrwith( 2 0.755929 NaN 3 0.576557 NaN """ + warnings.warn( + "DataFrameGroupBy.corrwith is deprecated", + FutureWarning, + stacklevel=find_stack_level(), + ) result = self._op_via_apply( "corrwith", other=other, diff --git a/pandas/tests/groupby/test_all_methods.py b/pandas/tests/groupby/test_all_methods.py index ad35bec70f668..a33da44f80396 100644 --- a/pandas/tests/groupby/test_all_methods.py +++ b/pandas/tests/groupby/test_all_methods.py @@ -25,9 +25,15 @@ def test_multiindex_group_all_columns_when_empty(groupby_func): gb = df.groupby(["a", "b", "c"], group_keys=False) method = getattr(gb, groupby_func) args = get_groupby_method_args(groupby_func, df) - - warn = FutureWarning if groupby_func == "fillna" else None - warn_msg = "DataFrameGroupBy.fillna is deprecated" + if groupby_func == "fillna": + warn = FutureWarning + warn_msg = "DataFrameGroupBy.fillna is deprecated" + elif groupby_func == "corrwith": + warn = FutureWarning + warn_msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + warn_msg = "" with tm.assert_produces_warning(warn, match=warn_msg): result = method(*args).index expected = df.index @@ -74,8 +80,15 @@ def test_dup_labels_output_shape(groupby_func, idx): grp_by = df.groupby([0]) args = get_groupby_method_args(groupby_func, df) - warn = FutureWarning if groupby_func == "fillna" else None - warn_msg = "DataFrameGroupBy.fillna is deprecated" + if groupby_func == "fillna": + warn = FutureWarning + warn_msg = "DataFrameGroupBy.fillna is deprecated" + elif groupby_func == "corrwith": + warn = FutureWarning + warn_msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + warn_msg = "" with tm.assert_produces_warning(warn, match=warn_msg): result = getattr(grp_by, groupby_func)(*args) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index e27c782c1bdcf..82e60946a9bed 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -1184,7 +1184,14 @@ def test_apply_is_unchanged_when_other_methods_are_called_first(reduction_func): # Check output when another method is called before .apply() grp = df.groupby(by="a") args = get_groupby_method_args(reduction_func, df) - _ = getattr(grp, reduction_func)(*args) + if reduction_func == "corrwith": + warn = FutureWarning + msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + msg = "" + with tm.assert_produces_warning(warn, match=msg): + _ = getattr(grp, reduction_func)(*args) result = grp.apply(np.sum, axis=0, include_groups=False) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 5a43a42aa936f..6e6d3d83a82f2 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1450,7 +1450,14 @@ def test_dataframe_groupby_on_2_categoricals_when_observed_is_true(reduction_fun df_grp = df.groupby(["cat_1", "cat_2"], observed=True) args = get_groupby_method_args(reduction_func, df) - res = getattr(df_grp, reduction_func)(*args) + if reduction_func == "corrwith": + warn = FutureWarning + warn_msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + warn_msg = "" + with tm.assert_produces_warning(warn, match=warn_msg): + res = getattr(df_grp, reduction_func)(*args) for cat in unobserved_cats: assert cat not in res.index @@ -1488,8 +1495,15 @@ def test_dataframe_groupby_on_2_categoricals_when_observed_is_false( ): getattr(df_grp, reduction_func)(*args) return - - res = getattr(df_grp, reduction_func)(*args) + + if reduction_func == "corrwith": + warn = FutureWarning + warn_msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + warn_msg = "" + with tm.assert_produces_warning(warn, match=warn_msg): + res = getattr(df_grp, reduction_func)(*args) expected = _results_for_groupbys_with_missing_categories[reduction_func] @@ -1881,8 +1895,14 @@ def test_category_order_reducer( ): getattr(gb, reduction_func)(*args) return - - op_result = getattr(gb, reduction_func)(*args) + if reduction_func == "corrwith": + warn = FutureWarning + warn_msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + warn_msg = "" + with tm.assert_produces_warning(warn, match=warn_msg): + op_result = getattr(gb, reduction_func)(*args) if as_index: result = op_result.index.get_level_values("a").categories else: diff --git a/pandas/tests/groupby/test_groupby_dropna.py b/pandas/tests/groupby/test_groupby_dropna.py index d3b3c945e06de..348abab38a5c8 100644 --- a/pandas/tests/groupby/test_groupby_dropna.py +++ b/pandas/tests/groupby/test_groupby_dropna.py @@ -543,7 +543,14 @@ def test_categorical_reducers(reduction_func, observed, sort, as_index, index_ki return gb_filled = df_filled.groupby(keys, observed=observed, sort=sort, as_index=True) - expected = getattr(gb_filled, reduction_func)(*args_filled).reset_index() + if reduction_func == "corrwith": + warn = FutureWarning + msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + msg = "" + with tm.assert_produces_warning(warn, match=msg): + expected = getattr(gb_filled, reduction_func)(*args_filled).reset_index() expected["x"] = expected["x"].cat.remove_categories([4]) if index_kind == "multi": expected["x2"] = expected["x2"].cat.remove_categories([4]) @@ -566,8 +573,15 @@ def test_categorical_reducers(reduction_func, observed, sort, as_index, index_ki expected = expected.rename(columns={0: "size"}) if as_index: expected = expected["size"].rename(None) - - result = getattr(gb_keepna, reduction_func)(*args) + + if reduction_func == "corrwith": + warn = FutureWarning + msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + msg = "" + with tm.assert_produces_warning(warn, match=msg): + result = getattr(gb_keepna, reduction_func)(*args) # size will return a Series, others are DataFrame tm.assert_equal(result, expected) diff --git a/pandas/tests/groupby/test_numeric_only.py b/pandas/tests/groupby/test_numeric_only.py index 33cdd1883e1b9..90b75f72f1f93 100644 --- a/pandas/tests/groupby/test_numeric_only.py +++ b/pandas/tests/groupby/test_numeric_only.py @@ -256,7 +256,14 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys): method = getattr(gb, kernel) if has_arg and numeric_only is True: # Cases where b does not appear in the result - result = method(*args, **kwargs) + if kernel == "corrwith": + warn = FutureWarning + msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + msg = "" + with tm.assert_produces_warning(warn, match=msg): + result = method(*args, **kwargs) assert "b" not in result.columns elif ( # kernels that work on any dtype and have numeric_only arg @@ -296,7 +303,14 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys): elif kernel == "idxmax": msg = "'>' not supported between instances of 'type' and 'type'" with pytest.raises(exception, match=msg): - method(*args, **kwargs) + if kernel == "corrwith": + warn = FutureWarning + msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + msg = "" + with tm.assert_produces_warning(warn, match=msg): + method(*args, **kwargs) elif not has_arg and numeric_only is not lib.no_default: with pytest.raises( TypeError, match="got an unexpected keyword argument 'numeric_only'" diff --git a/pandas/tests/groupby/test_raises.py b/pandas/tests/groupby/test_raises.py index 9301f8d56d9d2..5a8192a9ffe02 100644 --- a/pandas/tests/groupby/test_raises.py +++ b/pandas/tests/groupby/test_raises.py @@ -183,6 +183,8 @@ def test_groupby_raises_string( if groupby_func == "fillna": kind = "Series" if groupby_series else "DataFrame" warn_msg = f"{kind}GroupBy.fillna is deprecated" + elif groupby_func == "corrwith": + warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn_msg = "" _call_and_check(klass, msg, how, gb, groupby_func, args, warn_msg) @@ -288,6 +290,8 @@ def test_groupby_raises_datetime( if groupby_func == "fillna": kind = "Series" if groupby_series else "DataFrame" warn_msg = f"{kind}GroupBy.fillna is deprecated" + elif groupby_func == "corrwith": + warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn_msg = "" _call_and_check(klass, msg, how, gb, groupby_func, args, warn_msg=warn_msg) @@ -485,6 +489,8 @@ def test_groupby_raises_category( if groupby_func == "fillna": kind = "Series" if groupby_series else "DataFrame" warn_msg = f"{kind}GroupBy.fillna is deprecated" + elif groupby_func == "corrwith": + warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn_msg = "" _call_and_check(klass, msg, how, gb, groupby_func, args, warn_msg) @@ -658,6 +664,8 @@ def test_groupby_raises_category_on_category( if groupby_func == "fillna": kind = "Series" if groupby_series else "DataFrame" warn_msg = f"{kind}GroupBy.fillna is deprecated" + elif groupby_func == "corrwith": + warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn_msg = "" _call_and_check(klass, msg, how, gb, groupby_func, args, warn_msg) diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index d6d545a8c4834..da5437ab43354 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -1104,7 +1104,14 @@ def test_transform_agg_by_name(request, reduction_func, frame_or_series): return args = get_groupby_method_args(reduction_func, obj) - result = g.transform(func, *args) + if func == "corrwith": + warn = FutureWarning + msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + msg = "" + with tm.assert_produces_warning(warn, match=msg): + result = g.transform(func, *args) # this is the *definition* of a transformation tm.assert_index_equal(result.index, obj.index) @@ -1468,8 +1475,15 @@ def test_as_index_no_change(keys, df, groupby_func): args = get_groupby_method_args(groupby_func, df) gb_as_index_true = df.groupby(keys, as_index=True) gb_as_index_false = df.groupby(keys, as_index=False) - warn = FutureWarning if groupby_func == "fillna" else None - msg = "DataFrameGroupBy.fillna is deprecated" + if groupby_func == "fillna": + warn = FutureWarning + msg = "DataFrameGroupBy.fillna is deprecated" + elif groupby_func == "corrwith": + warn = FutureWarning + msg = "DataFrameGroupBy.corrwith is deprecated" + else: + warn = None + msg = "" with tm.assert_produces_warning(warn, match=msg): result = gb_as_index_true.transform(groupby_func, *args) with tm.assert_produces_warning(warn, match=msg): From 695f418cdd1aa51a05edab507a0d7bbf9d7e4885 Mon Sep 17 00:00:00 2001 From: pedrocariellof Date: Wed, 15 May 2024 01:04:33 -0300 Subject: [PATCH 2/9] Deprecation of groupby.corrwith --- pandas/core/groupby/generic.py | 4 ++-- pandas/tests/groupby/test_all_methods.py | 4 ++-- pandas/tests/groupby/test_apply.py | 2 +- pandas/tests/groupby/test_categorical.py | 8 ++++---- pandas/tests/groupby/test_groupby_dropna.py | 6 +++--- pandas/tests/groupby/test_numeric_only.py | 4 ++-- pandas/tests/groupby/transform/test_transform.py | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 83793df7c601c..32eb4ecb1a799 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -21,19 +21,19 @@ Union, cast, ) +import warnings import numpy as np -import warnings from pandas._libs import Interval from pandas._libs.hashtable import duplicated from pandas.errors import SpecificationError -from pandas.util._exceptions import find_stack_level from pandas.util._decorators import ( Appender, Substitution, doc, ) +from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.common import ( ensure_int64, diff --git a/pandas/tests/groupby/test_all_methods.py b/pandas/tests/groupby/test_all_methods.py index a33da44f80396..d650b71771e7c 100644 --- a/pandas/tests/groupby/test_all_methods.py +++ b/pandas/tests/groupby/test_all_methods.py @@ -31,7 +31,7 @@ def test_multiindex_group_all_columns_when_empty(groupby_func): elif groupby_func == "corrwith": warn = FutureWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None warn_msg = "" with tm.assert_produces_warning(warn, match=warn_msg): @@ -86,7 +86,7 @@ def test_dup_labels_output_shape(groupby_func, idx): elif groupby_func == "corrwith": warn = FutureWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None warn_msg = "" with tm.assert_produces_warning(warn, match=warn_msg): diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 82e60946a9bed..306dadf20d0fb 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -1187,7 +1187,7 @@ def test_apply_is_unchanged_when_other_methods_are_called_first(reduction_func): if reduction_func == "corrwith": warn = FutureWarning msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None msg = "" with tm.assert_produces_warning(warn, match=msg): diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 6e6d3d83a82f2..34d70d25827f9 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1453,7 +1453,7 @@ def test_dataframe_groupby_on_2_categoricals_when_observed_is_true(reduction_fun if reduction_func == "corrwith": warn = FutureWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None warn_msg = "" with tm.assert_produces_warning(warn, match=warn_msg): @@ -1495,11 +1495,11 @@ def test_dataframe_groupby_on_2_categoricals_when_observed_is_false( ): getattr(df_grp, reduction_func)(*args) return - + if reduction_func == "corrwith": warn = FutureWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None warn_msg = "" with tm.assert_produces_warning(warn, match=warn_msg): @@ -1898,7 +1898,7 @@ def test_category_order_reducer( if reduction_func == "corrwith": warn = FutureWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None warn_msg = "" with tm.assert_produces_warning(warn, match=warn_msg): diff --git a/pandas/tests/groupby/test_groupby_dropna.py b/pandas/tests/groupby/test_groupby_dropna.py index 348abab38a5c8..4749e845a0e59 100644 --- a/pandas/tests/groupby/test_groupby_dropna.py +++ b/pandas/tests/groupby/test_groupby_dropna.py @@ -546,7 +546,7 @@ def test_categorical_reducers(reduction_func, observed, sort, as_index, index_ki if reduction_func == "corrwith": warn = FutureWarning msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None msg = "" with tm.assert_produces_warning(warn, match=msg): @@ -573,11 +573,11 @@ def test_categorical_reducers(reduction_func, observed, sort, as_index, index_ki expected = expected.rename(columns={0: "size"}) if as_index: expected = expected["size"].rename(None) - + if reduction_func == "corrwith": warn = FutureWarning msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None msg = "" with tm.assert_produces_warning(warn, match=msg): diff --git a/pandas/tests/groupby/test_numeric_only.py b/pandas/tests/groupby/test_numeric_only.py index 90b75f72f1f93..afbc64429e93c 100644 --- a/pandas/tests/groupby/test_numeric_only.py +++ b/pandas/tests/groupby/test_numeric_only.py @@ -259,7 +259,7 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys): if kernel == "corrwith": warn = FutureWarning msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None msg = "" with tm.assert_produces_warning(warn, match=msg): @@ -306,7 +306,7 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys): if kernel == "corrwith": warn = FutureWarning msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None msg = "" with tm.assert_produces_warning(warn, match=msg): diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index da5437ab43354..a6fc630f71861 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -1481,7 +1481,7 @@ def test_as_index_no_change(keys, df, groupby_func): elif groupby_func == "corrwith": warn = FutureWarning msg = "DataFrameGroupBy.corrwith is deprecated" - else: + else: warn = None msg = "" with tm.assert_produces_warning(warn, match=msg): From b37044101a85c4f2edf990bee4a43688a1222b27 Mon Sep 17 00:00:00 2001 From: pedrocariellof Date: Thu, 16 May 2024 12:19:57 -0300 Subject: [PATCH 3/9] Deprecation of groupby.corrwith --- pandas/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/conftest.py b/pandas/conftest.py index e1225f031b568..25e7298145dc1 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -150,6 +150,7 @@ def pytest_collection_modifyitems(items, config) -> None: ("is_categorical_dtype", "is_categorical_dtype is deprecated"), ("is_sparse", "is_sparse is deprecated"), ("DataFrameGroupBy.fillna", "DataFrameGroupBy.fillna is deprecated"), + ("DataFrameGroupBy.corrwith", "DataFrameGroupBy.corrwith is deprecated"), ("NDFrame.replace", "Series.replace without 'value'"), ("NDFrame.clip", "Downcasting behavior in Series and DataFrame methods"), ("Series.idxmin", "The behavior of Series.idxmin"), From b546c468f5478054b20515f93783ed41411bfc6d Mon Sep 17 00:00:00 2001 From: pedrocariellof Date: Thu, 16 May 2024 13:21:17 -0300 Subject: [PATCH 4/9] Deprecation of groupby.corrwith --- doc/source/development/policies.rst | 2 -- doc/source/getting_started/install.rst | 4 ++-- doc/source/whatsnew/v3.0.0.rst | 2 +- pandas/core/groupby/generic.py | 2 ++ pandas/tests/groupby/test_all_methods.py | 20 ++++--------------- .../tests/groupby/transform/test_transform.py | 5 +---- 6 files changed, 10 insertions(+), 25 deletions(-) diff --git a/doc/source/development/policies.rst b/doc/source/development/policies.rst index f958e4c4ad1fc..8465820452353 100644 --- a/doc/source/development/policies.rst +++ b/doc/source/development/policies.rst @@ -46,8 +46,6 @@ deprecation removed in the next major release (2.0.0). These policies do not apply to features marked as **experimental** in the documentation. pandas may change the behavior of experimental features at any time. -.. _policies.python_support: - Python support ~~~~~~~~~~~~~~ diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index 01a79fc8e36fd..ac9dd08702c5e 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -1,4 +1,4 @@ -.. _install: + .. _install: {{ header }} @@ -21,7 +21,7 @@ Instructions for installing :ref:`from source `, Python version support ---------------------- -See :ref:`Python support policy `. +Officially Python 3.9, 3.10, 3.11 and 3.12. Installing pandas ----------------- diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index a8d46dd9125a2..20e7ca99360ce 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -171,7 +171,6 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- Deprecated :meth:`Groupby.corrwith` (:issue:`57158`) Copy keyword ^^^^^^^^^^^^ @@ -202,6 +201,7 @@ starting with 3.0, so it can be safely removed from your code. Other Deprecations ^^^^^^^^^^^^^^^^^^ +- Deprecated :meth:`Groupby.corrwith` (:issue:`57158`) - Deprecated :meth:`Timestamp.utcfromtimestamp`, use ``Timestamp.fromtimestamp(ts, "UTC")`` instead (:issue:`56680`) - Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.all`, :meth:`DataFrame.min`, :meth:`DataFrame.max`, :meth:`DataFrame.sum`, :meth:`DataFrame.prod`, :meth:`DataFrame.mean`, :meth:`DataFrame.median`, :meth:`DataFrame.sem`, :meth:`DataFrame.var`, :meth:`DataFrame.std`, :meth:`DataFrame.skew`, :meth:`DataFrame.kurt`, :meth:`Series.all`, :meth:`Series.min`, :meth:`Series.max`, :meth:`Series.sum`, :meth:`Series.prod`, :meth:`Series.mean`, :meth:`Series.median`, :meth:`Series.sem`, :meth:`Series.var`, :meth:`Series.std`, :meth:`Series.skew`, and :meth:`Series.kurt`. (:issue:`57087`) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 32eb4ecb1a799..e6542727ad940 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -2733,6 +2733,8 @@ def corrwith( are first aligned along both axes before computing the correlations. + .. deprecated:: 3.0.0 + Parameters ---------- other : DataFrame, Series diff --git a/pandas/tests/groupby/test_all_methods.py b/pandas/tests/groupby/test_all_methods.py index d650b71771e7c..945c3e421a132 100644 --- a/pandas/tests/groupby/test_all_methods.py +++ b/pandas/tests/groupby/test_all_methods.py @@ -25,10 +25,7 @@ def test_multiindex_group_all_columns_when_empty(groupby_func): gb = df.groupby(["a", "b", "c"], group_keys=False) method = getattr(gb, groupby_func) args = get_groupby_method_args(groupby_func, df) - if groupby_func == "fillna": - warn = FutureWarning - warn_msg = "DataFrameGroupBy.fillna is deprecated" - elif groupby_func == "corrwith": + if groupby_func == "corrwith": warn = FutureWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: @@ -48,18 +45,12 @@ def test_duplicate_columns(request, groupby_func, as_index): df = DataFrame([[1, 3, 6], [1, 4, 7], [2, 5, 8]], columns=list("abb")) args = get_groupby_method_args(groupby_func, df) gb = df.groupby("a", as_index=as_index) - warn = FutureWarning if groupby_func == "fillna" else None - warn_msg = "DataFrameGroupBy.fillna is deprecated" - with tm.assert_produces_warning(warn, match=warn_msg): - result = getattr(gb, groupby_func)(*args) + result = getattr(gb, groupby_func)(*args) expected_df = df.set_axis(["a", "b", "c"], axis=1) expected_args = get_groupby_method_args(groupby_func, expected_df) expected_gb = expected_df.groupby("a", as_index=as_index) - warn = FutureWarning if groupby_func == "fillna" else None - warn_msg = "DataFrameGroupBy.fillna is deprecated" - with tm.assert_produces_warning(warn, match=warn_msg): - expected = getattr(expected_gb, groupby_func)(*expected_args) + expected = getattr(expected_gb, groupby_func)(*expected_args) if groupby_func not in ("size", "ngroup", "cumcount"): expected = expected.rename(columns={"c": "b"}) tm.assert_equal(result, expected) @@ -80,10 +71,7 @@ def test_dup_labels_output_shape(groupby_func, idx): grp_by = df.groupby([0]) args = get_groupby_method_args(groupby_func, df) - if groupby_func == "fillna": - warn = FutureWarning - warn_msg = "DataFrameGroupBy.fillna is deprecated" - elif groupby_func == "corrwith": + if groupby_func == "corrwith": warn = FutureWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index a6fc630f71861..726c57081373c 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -1475,10 +1475,7 @@ def test_as_index_no_change(keys, df, groupby_func): args = get_groupby_method_args(groupby_func, df) gb_as_index_true = df.groupby(keys, as_index=True) gb_as_index_false = df.groupby(keys, as_index=False) - if groupby_func == "fillna": - warn = FutureWarning - msg = "DataFrameGroupBy.fillna is deprecated" - elif groupby_func == "corrwith": + if groupby_func == "corrwith": warn = FutureWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: From ddf9dd620c5ff907743389e1f91a47633586a5b7 Mon Sep 17 00:00:00 2001 From: pedrocariellof Date: Sun, 26 May 2024 23:23:25 -0300 Subject: [PATCH 5/9] Adjusting docstring of generic.py --- pandas/core/groupby/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index e6542727ad940..d986f0a1350fb 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -2726,6 +2726,8 @@ def corrwith( numeric_only: bool = False, ) -> DataFrame: """ + .. deprecated:: 3.0.0 + Compute pairwise correlation. Pairwise correlation is computed between rows or columns of @@ -2733,8 +2735,6 @@ def corrwith( are first aligned along both axes before computing the correlations. - .. deprecated:: 3.0.0 - Parameters ---------- other : DataFrame, Series From d8352cdc9c6e290f01cf1ebff12afd828326d4d0 Mon Sep 17 00:00:00 2001 From: pedrocariellof Date: Sun, 26 May 2024 23:50:02 -0300 Subject: [PATCH 6/9] Adjusting docstring of generic.py --- pandas/core/groupby/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index d986f0a1350fb..4300cc91a17f7 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -2726,10 +2726,10 @@ def corrwith( numeric_only: bool = False, ) -> DataFrame: """ - .. deprecated:: 3.0.0 - Compute pairwise correlation. + .. deprecated:: 3.0.0 + Pairwise correlation is computed between rows or columns of DataFrame with rows or columns of Series or DataFrame. DataFrames are first aligned along both axes before computing the From 626f3efeaa1079fb3f3f32771594354e69851f4e Mon Sep 17 00:00:00 2001 From: Thomaz Miranda <43679181+tomytp@users.noreply.github.com> Date: Fri, 31 May 2024 18:20:18 -0300 Subject: [PATCH 7/9] Update doc/source/whatsnew/v3.0.0.rst Co-authored-by: Richard Shadrach <45562402+rhshadrach@users.noreply.github.com> --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 644fe05caffc4..553d2f00536d1 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -264,7 +264,7 @@ starting with 3.0, so it can be safely removed from your code. Other Deprecations ^^^^^^^^^^^^^^^^^^ -- Deprecated :meth:`Groupby.corrwith` (:issue:`57158`) +- Deprecated :meth:`.DataFrameGroupby.corrwith` (:issue:`57158`) - Deprecated :meth:`Timestamp.utcfromtimestamp`, use ``Timestamp.fromtimestamp(ts, "UTC")`` instead (:issue:`56680`) - Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.all`, :meth:`DataFrame.min`, :meth:`DataFrame.max`, :meth:`DataFrame.sum`, :meth:`DataFrame.prod`, :meth:`DataFrame.mean`, :meth:`DataFrame.median`, :meth:`DataFrame.sem`, :meth:`DataFrame.var`, :meth:`DataFrame.std`, :meth:`DataFrame.skew`, :meth:`DataFrame.kurt`, :meth:`Series.all`, :meth:`Series.min`, :meth:`Series.max`, :meth:`Series.sum`, :meth:`Series.prod`, :meth:`Series.mean`, :meth:`Series.median`, :meth:`Series.sem`, :meth:`Series.var`, :meth:`Series.std`, :meth:`Series.skew`, and :meth:`Series.kurt`. (:issue:`57087`) From 899f66de2ff91b7056af507fd0b0498a1a10fe9b Mon Sep 17 00:00:00 2001 From: Thomaz Miranda <43679181+tomytp@users.noreply.github.com> Date: Fri, 31 May 2024 18:22:16 -0300 Subject: [PATCH 8/9] Update install.rst --- doc/source/getting_started/install.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index 506b263521503..01a79fc8e36fd 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -1,4 +1,4 @@ - .. _install: +.. _install: {{ header }} From 3cc37b23279a343cea2b55eacf96665e84e15ae1 Mon Sep 17 00:00:00 2001 From: Thomaz Miranda <43679181+tomytp@users.noreply.github.com> Date: Fri, 31 May 2024 18:24:21 -0300 Subject: [PATCH 9/9] Update v3.0.0.rst --- doc/source/whatsnew/v3.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 553d2f00536d1..f5faf67304022 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -234,7 +234,6 @@ Other API changes Deprecations ~~~~~~~~~~~~ - Copy keyword ^^^^^^^^^^^^