@@ -371,24 +371,9 @@ def _call_cython_op(
371
371
372
372
is_datetimelike = dtype .kind in "mM"
373
373
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
-
380
374
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
392
377
elif dtype .kind == "b" :
393
378
values = values .view ("uint8" )
394
379
if values .dtype == "float16" :
@@ -400,6 +385,19 @@ def _call_cython_op(
400
385
if result_mask is not None :
401
386
result_mask = result_mask .T
402
387
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
+
403
401
out_shape = self ._get_output_shape (ngroups , values )
404
402
func = self ._get_cython_function (self .kind , self .how , values .dtype , is_numeric )
405
403
values = self ._get_cython_vals (values )
0 commit comments