diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 6d41c29a6c614..ebcfd16f92d29 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -96,6 +96,13 @@ Deprecations - Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`) - +.. --------------------------------------------------------------------------- +.. _whatsnew_300.prior_deprecations: + +Removal of prior version deprecations/changes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`) + .. --------------------------------------------------------------------------- .. _whatsnew_300.performance: diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 7227d5c727994..1ca2b4ff511ca 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1049,7 +1049,7 @@ def pipe( return com.pipe(self, func, *args, **kwargs) @final - def get_group(self, name, obj=None) -> DataFrame | Series: + def get_group(self, name) -> DataFrame | Series: """ Construct DataFrame from group with provided name. @@ -1057,19 +1057,10 @@ def get_group(self, name, obj=None) -> DataFrame | Series: ---------- name : object The name of the group to get as a DataFrame. - obj : DataFrame, default None - The DataFrame to take the DataFrame out of. If - it is None, the object groupby was called on will - be used. - - .. deprecated:: 2.1.0 - The obj is deprecated and will be removed in a future version. - Do ``df.iloc[gb.indices.get(name)]`` - instead of ``gb.get_group(name, obj=df)``. Returns ------- - same type as obj + DataFrame or Series Examples -------- @@ -1142,18 +1133,8 @@ def get_group(self, name, obj=None) -> DataFrame | Series: if not len(inds): raise KeyError(name) - if obj is None: - indexer = inds if self.axis == 0 else (slice(None), inds) - return self._selected_obj.iloc[indexer] - else: - warnings.warn( - "obj is deprecated and will be removed in a future version. " - "Do ``df.iloc[gb.indices.get(name)]`` " - "instead of ``gb.get_group(name, obj=df)``.", - FutureWarning, - stacklevel=find_stack_level(), - ) - return obj._take_with_is_copy(inds, axis=self.axis) + indexer = inds if self.axis == 0 else (slice(None), inds) + return self._selected_obj.iloc[indexer] @final def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]: diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 14866ce2065ed..7f7d9544c3891 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -526,16 +526,6 @@ def test_as_index_select_column(): tm.assert_series_equal(result, expected) -def test_obj_arg_get_group_deprecated(): - depr_msg = "obj is deprecated" - - df = DataFrame({"a": [1, 1, 2], "b": [3, 4, 5]}) - expected = df.iloc[df.groupby("b").indices.get(4)] - with tm.assert_produces_warning(FutureWarning, match=depr_msg): - result = df.groupby("b").get_group(4, obj=df) - tm.assert_frame_equal(result, expected) - - def test_groupby_as_index_select_column_sum_empty_df(): # GH 35246 df = DataFrame(columns=Index(["A", "B", "C"], name="alpha"))