Skip to content

Commit

Permalink
DEPR: removed deprecated argument obj from GroupBy get_group (#57136
Browse files Browse the repository at this point in the history
)
  • Loading branch information
natmokval authored Jan 31, 2024
1 parent c811353 commit db11e25
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
7 changes: 7 additions & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
27 changes: 4 additions & 23 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,27 +1049,18 @@ 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.
Parameters
----------
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
--------
Expand Down Expand Up @@ -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]]:
Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit db11e25

Please sign in to comment.