@@ -371,34 +371,29 @@ def _call_cython_op(
371
371
372
372
is_datetimelike = dtype .kind in "mM"
373
373
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 )
376
378
is_numeric = True
377
379
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
383
391
384
392
elif dtype .kind == "b" :
385
393
values = values .view ("uint8" )
386
394
if values .dtype == "float16" :
387
395
values = values .astype (np .float32 )
388
396
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
-
402
397
values = values .T
403
398
if mask is not None :
404
399
mask = mask .T
0 commit comments