Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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:`GroupBy.get_group` (:issue:`53545`)
Copy link
Member

@rhshadrach rhshadrach Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to resolve a link to the documentation, can you replace the end with

:meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, I corrected the note in v3.0.0.rst


.. ---------------------------------------------------------------------------
.. _whatsnew_300.performance:

Expand Down
18 changes: 5 additions & 13 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,15 +1062,14 @@ 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

Raises
------
ValueError : The passed argument obj is not None.

Examples
--------

Expand Down Expand Up @@ -1146,14 +1145,7 @@ def get_group(self, name, obj=None) -> DataFrame | Series:
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)
raise ValueError("cannot pass argument obj to get_group")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I missed any conversations on this but I am fairly certain you can just remove the obj=None parameter from the function definition and then remove this if...else block altogether

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, I removed the parameter obj from the definition of get_group, the block if...else and corrected docstring.


@final
def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]:
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,11 @@ def test_as_index_select_column():


def test_obj_arg_get_group_deprecated():
depr_msg = "obj is deprecated"
msg = "cannot pass argument obj to get_group"

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)
with pytest.raises(ValueError, match=msg):
df.groupby("b").get_group(4, obj=df)


def test_groupby_as_index_select_column_sum_empty_df():
Expand Down