Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions python/cudf/cudf/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,27 @@ def _wrap_idxmin_idxmax(self, result: DataFrame | Series, *, skipna: bool):
raise ValueError(
"Encountered all NA values in a group with skipna=True"
)
# idxmin/idxmax return positional/label indices, which take their
# dtype from the source object's row index — not from the values
# being reduced. Cast the (non-key) result columns accordingly to
# match pandas, where reducing an Int64 column still yields int64
# indices for a default RangeIndex. Skip the cast when the source
# uses a MultiIndex (no single representative dtype) to avoid
# lossy/unsupported casts.
from cudf.core.multiindex import MultiIndex

if isinstance(self.obj.index, MultiIndex):
return result
index_dtype = self.obj.index.dtype
key_names = set(self.grouping.names)
if result.ndim == 2:
for name, col in result._column_labels_and_values:
if name in key_names:
continue
if col.dtype != index_dtype:
result._data[name] = col.astype(index_dtype)
elif result.dtype != index_dtype:
result = result.astype(index_dtype)
return result

def _reduce_numeric_only(self, op: str):
Expand Down
Loading
Loading