Skip to content

Commit 9c1b4ce

Browse files
Avoid casting in specific situations
1 parent ae1ab89 commit 9c1b4ce

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/core/groupby/generic.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ def _aggregate_item_by_item(self, func, *args, **kwargs):
254254
data = obj[item]
255255
colg = SeriesGroupBy(data, selection=item,
256256
grouper=self.grouper)
257-
result[item] = self._try_cast(
258-
colg.aggregate(func, *args, **kwargs), data)
257+
258+
result[item] = colg.aggregate(func, *args, **kwargs)
259+
if func != "idxmin" and func != "idxmax":
260+
result[item] = self._try_cast(result[item], data)
261+
259262
except ValueError:
260263
cannot_agg.append(item)
261264
continue

0 commit comments

Comments
 (0)