Skip to content

BUG: GroupBy.idxmax/idxmin with EA dtypes #38733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 19, 2021
8 changes: 6 additions & 2 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def argsort(
mask=np.asarray(self.isna()),
)

def argmin(self):
def argmin(self, axis=None, skipna: bool = True):
Copy link
Member

Choose a reason for hiding this comment

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

The axis keyword shouldn't be added, since it's being ignored. It can be accepted through args/kwargs, and then validated with our numpy compat (+ tests for the numpy compat)

"""
Return the index of minimum value.

Expand All @@ -611,9 +611,11 @@ def argmin(self):
--------
ExtensionArray.argmax
"""
if not skipna:
raise NotImplementedError
return nargminmax(self, "argmin")

def argmax(self):
def argmax(self, axis=None, skipna: bool = True):
"""
Return the index of maximum value.

Expand All @@ -628,6 +630,8 @@ def argmax(self):
--------
ExtensionArray.argmin
"""
if not skipna:
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test that hits this (and argmin)

return nargminmax(self, "argmax")

def fillna(self, value=None, method=None, limit=None):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/groupby/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,16 @@ def test_idxmin_idxmax_returns_int_types(func, values):
}
)
df["c_date"] = pd.to_datetime(df["c_date"])
df["c_date_tz"] = df["c_date"].dt.tz_localize("US/Pacific")
df["c_timedelta"] = df["c_date"] - df["c_date"].iloc[0]
df["c_period"] = df["c_date"].dt.to_period("W")

result = getattr(df.groupby("name"), func)()

expected = DataFrame(values, index=Index(["A", "B"], name="name"))
expected["c_date_tz"] = expected["c_date"]
expected["c_timedelta"] = expected["c_date"]
expected["c_period"] = expected["c_date"]

tm.assert_frame_equal(result, expected)

Expand Down