Skip to content

Commit ca40652

Browse files
committed
changed ops.py to correct mypy error
1 parent 28b5450 commit ca40652

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

pandas/core/groupby/ops.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -371,34 +371,29 @@ def _call_cython_op(
371371

372372
is_datetimelike = dtype.kind in "mM"
373373

374-
if is_datetimelike:
375-
values = values.view("int64")
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)
376378
is_numeric = True
377379

378-
# Fix for NaT handling: ensure NaT is treated as False in any() and all()
379-
if self.how in ["any", "all"]:
380-
# Set NaT (which is represented as the smallest int64) to False (0)
381-
nat_mask = values == np.iinfo(np.int64).min
382-
values[nat_mask] = 0 # Treat NaT as False
380+
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
383391

384392
elif dtype.kind == "b":
385393
values = values.view("uint8")
386394
if values.dtype == "float16":
387395
values = values.astype(np.float32)
388396

389-
if self.how in ["any", "all"]:
390-
if mask is None:
391-
mask = isna(values)
392-
if dtype == object:
393-
if kwargs["skipna"]:
394-
# GH#37501: don't raise on pd.NA when skipna=True
395-
if mask.any():
396-
# mask on original values computed separately
397-
values = values.copy()
398-
values[mask] = True
399-
values = values.astype(bool, copy=False).view(np.int8)
400-
is_numeric = True
401-
402397
values = values.T
403398
if mask is not None:
404399
mask = mask.T

0 commit comments

Comments
 (0)