From 56137f7431e09f7485fcdffb21681bac56b7d4d5 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:19:03 -0400 Subject: [PATCH 1/3] DEPR: Change FutureWarning for observed=False to DeprecationWarning --- doc/source/whatsnew/v2.1.1.rst | 1 + pandas/core/groupby/groupby.py | 2 +- pandas/tests/groupby/test_categorical.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.1.1.rst b/doc/source/whatsnew/v2.1.1.rst index c52f7db8ec3ec..0f3ee6cf582d9 100644 --- a/doc/source/whatsnew/v2.1.1.rst +++ b/doc/source/whatsnew/v2.1.1.rst @@ -44,6 +44,7 @@ Bug fixes Other ~~~~~ +- Changed the ``FutureWarning`` raised when ``observed=False`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to a ``DeprecationWarning`` (:issue:`54970`) - Reverted the deprecation that disallowed :meth:`Series.apply` returning a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object (:issue:`52116`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index d607baf18d6cb..942358b6db3de 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1322,7 +1322,7 @@ def __init__( "to True in a future version of pandas. Pass observed=False to " "retain current behavior or observed=True to adopt the future " "default and silence this warning.", - FutureWarning, + DeprecationWarning, stacklevel=find_stack_level(), ) observed = False diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index b11240c841420..cb083eed4c2fc 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -2080,7 +2080,7 @@ def test_groupby_default_depr(cat_columns, keys): df = DataFrame({"a": [1, 1, 2, 3], "b": [4, 5, 6, 7]}) df[cat_columns] = df[cat_columns].astype("category") msg = "The default of observed=False is deprecated" - klass = FutureWarning if set(cat_columns) & set(keys) else None + klass = DeprecationWarning if set(cat_columns) & set(keys) else None with tm.assert_produces_warning(klass, match=msg): df.groupby(keys) From 9d7f4a1863bd369e7182d48318f81ebdd32ccb3c Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:22:51 -0400 Subject: [PATCH 2/3] move note --- doc/source/whatsnew/v2.1.1.rst | 1 - doc/source/whatsnew/v2.1.2.rst | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.1.1.rst b/doc/source/whatsnew/v2.1.1.rst index 0f3ee6cf582d9..fd19277c36867 100644 --- a/doc/source/whatsnew/v2.1.1.rst +++ b/doc/source/whatsnew/v2.1.1.rst @@ -45,7 +45,6 @@ Bug fixes Other ~~~~~ - Changed the ``FutureWarning`` raised when ``observed=False`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to a ``DeprecationWarning`` (:issue:`54970`) -- Reverted the deprecation that disallowed :meth:`Series.apply` returning a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object (:issue:`52116`) .. --------------------------------------------------------------------------- .. _whatsnew_211.contributors: diff --git a/doc/source/whatsnew/v2.1.2.rst b/doc/source/whatsnew/v2.1.2.rst index 2c9b10160d144..c44374171f16d 100644 --- a/doc/source/whatsnew/v2.1.2.rst +++ b/doc/source/whatsnew/v2.1.2.rst @@ -29,7 +29,7 @@ Bug fixes Other ~~~~~ -- +- Reverted the deprecation that disallowed :meth:`Series.apply` returning a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object (:issue:`52116`) - .. --------------------------------------------------------------------------- From a8b9ac74bd755b1966a9e701c59c243f77a3c94c Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:25:28 -0400 Subject: [PATCH 3/3] swap order --- doc/source/whatsnew/v2.1.1.rst | 2 +- doc/source/whatsnew/v2.1.2.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.1.1.rst b/doc/source/whatsnew/v2.1.1.rst index fd19277c36867..c52f7db8ec3ec 100644 --- a/doc/source/whatsnew/v2.1.1.rst +++ b/doc/source/whatsnew/v2.1.1.rst @@ -44,7 +44,7 @@ Bug fixes Other ~~~~~ -- Changed the ``FutureWarning`` raised when ``observed=False`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to a ``DeprecationWarning`` (:issue:`54970`) +- Reverted the deprecation that disallowed :meth:`Series.apply` returning a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object (:issue:`52116`) .. --------------------------------------------------------------------------- .. _whatsnew_211.contributors: diff --git a/doc/source/whatsnew/v2.1.2.rst b/doc/source/whatsnew/v2.1.2.rst index c44374171f16d..bbf7368513fd4 100644 --- a/doc/source/whatsnew/v2.1.2.rst +++ b/doc/source/whatsnew/v2.1.2.rst @@ -29,7 +29,7 @@ Bug fixes Other ~~~~~ -- Reverted the deprecation that disallowed :meth:`Series.apply` returning a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object (:issue:`52116`) +- Changed the ``FutureWarning`` raised when ``observed=False`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to a ``DeprecationWarning`` (:issue:`54970`) - .. ---------------------------------------------------------------------------