Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ Deprecations
- Deprecated behavior of :func:`assert_series_equal` and :func:`assert_frame_equal` considering NA-like values (e.g. ``NaN`` vs ``None`` as equivalent) (:issue:`52081`)
- Deprecated constructing :class:`SparseArray` from scalar data, pass a sequence instead (:issue:`53039`)
- Deprecated option "mode.use_inf_as_na", convert inf entries to ``NaN`` before instead (:issue:`51684`)
- Deprecated parameter ``obj`` in :meth:`GroupBy.get_group` (:issue:`53545`)
- Deprecated positional indexing on :class:`Series` with :meth:`Series.__getitem__` and :meth:`Series.__setitem__`, in a future version ``ser[item]`` will *always* interpret ``item`` as a label, not a position (:issue:`50617`)

.. ---------------------------------------------------------------------------
Expand Down
20 changes: 16 additions & 4 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,11 @@ def get_group(self, name, obj=None) -> DataFrame | Series:
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
Expand Down Expand Up @@ -955,14 +960,21 @@ def get_group(self, name, obj=None) -> DataFrame | Series:
owl 1 2 3
toucan 1 5 6
"""
if obj is None:
obj = self._selected_obj

inds = self._get_index(name)
if not len(inds):
raise KeyError(name)

return obj._take_with_is_copy(inds, axis=self.axis)
if obj is None:
return self._selected_obj.iloc[inds]
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)

@final
def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]:
Expand Down