Skip to content

Commit ab6bf95

Browse files
committed
simpler solution
1 parent 5a3e722 commit ab6bf95

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

pandas/core/groupby/ops.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -371,24 +371,9 @@ def _call_cython_op(
371371

372372
is_datetimelike = dtype.kind in "mM"
373373

374-
if self.how in ["any", "all"]:
375-
if mask is None:
376-
mask = isna(values)
377-
values = values.astype(bool, copy=False).view(np.int8)
378-
is_numeric = True
379-
380374
if is_datetimelike:
381-
# Handle NaT values correctly
382-
if self.how == "any" and mask is not None:
383-
# For "any", we want True only if there's at least one non-NaT value
384-
values = (~mask).astype(np.int8) # Convert mask to int8
385-
elif self.how == "all" and mask is not None:
386-
# For "all", we want True only if all values are non-NaT
387-
values = (~mask).all(axis=1, keepdims=True).astype(np.int8)
388-
is_numeric = True
389-
else:
390-
values = values.view("int64") # Handle other cases appropriately
391-
375+
values = values.view("int64")
376+
is_numeric = True
392377
elif dtype.kind == "b":
393378
values = values.view("uint8")
394379
if values.dtype == "float16":
@@ -400,6 +385,19 @@ def _call_cython_op(
400385
if result_mask is not None:
401386
result_mask = result_mask.T
402387

388+
if self.how in ["any", "all"]:
389+
if mask is None:
390+
mask = isna(values)
391+
if dtype == object:
392+
if kwargs["skipna"]:
393+
# GH#37501: don't raise on pd.NA when skipna=True
394+
if mask.any():
395+
# mask on original values computed separately
396+
values = values.copy()
397+
values[mask] = True
398+
values = values.astype(bool, copy=False).view(np.int8)
399+
is_numeric = True
400+
403401
out_shape = self._get_output_shape(ngroups, values)
404402
func = self._get_cython_function(self.kind, self.how, values.dtype, is_numeric)
405403
values = self._get_cython_vals(values)

0 commit comments

Comments
 (0)