DEPR: obj
argument in GroupBy.get_group
· Issue #53545 · pandas-dev/pandas (original) (raw)
From the code:
def get_group(self, name, obj=None) -> 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.
Returns
-------
same type as obj
Getting the group of an object that is unrelated to the groupby seems unnecessary. Also the implementation appears to use the indices of the requested group from self._selected_obj
and return those indices (via integer location) in the passed obj
. This doesn't seem meaninful/useful.
I think we should deprecate this argument.
df = pd.DataFrame({'a': [1, 1, 2], 'b': [3, 4, 5]})
gb = df.groupby('a')
df2 = pd.DataFrame({'a': [3], 'b': [6]})
print(gb.get_group(1, obj=df2))
# IndexError: indices are out-of-bounds
print(gb.get_group(3, obj=df2))
# KeyError: 3