From caf7f42854b96c39b4593e361364b975246cff03 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:55:09 +0100 Subject: [PATCH] DEPR: Deprecate passing positional arguments in {DataFrame,Series}.groupby (except `by` and `level`) --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/core/frame.py | 3 +++ pandas/core/series.py | 3 +++ 3 files changed, 7 insertions(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 7eb7605a47aa1..5aec8339f51e6 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -514,6 +514,7 @@ Other Deprecations - Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`) - Deprecated ``pd.core.internals.api.maybe_infer_ndim`` (:issue:`40226`) - 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`) +- Deprecated allowing non-keyword arguments in :meth:`DataFrame.groupby` and :meth:`Series.groupby` except ``by`` and ``level``. (:issue:`62102`) - Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`) - Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`) - Deprecated behavior of :meth:`.DataFrameGroupBy.groups` and :meth:`.SeriesGroupBy.groups`, in a future version ``groups`` by one element list will return tuple instead of scalar. (:issue:`58858`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ec8c8116e5aee..72eb17b5fe7e1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9368,6 +9368,9 @@ def update( ) ) @Appender(_shared_docs["groupby"] % _shared_doc_kwargs) + @deprecate_nonkeyword_arguments( + Pandas4Warning, allowed_args=["self", "by", "level"], name="groupby" + ) def groupby( self, by=None, diff --git a/pandas/core/series.py b/pandas/core/series.py index 00cff09801f1a..40a01acac1f3c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1966,6 +1966,9 @@ def _set_name( ) ) @Appender(_shared_docs["groupby"] % _shared_doc_kwargs) + @deprecate_nonkeyword_arguments( + Pandas4Warning, allowed_args=["self", "by", "level"], name="groupby" + ) def groupby( self, by=None,