@@ -428,10 +428,37 @@ def nanany(values, axis=None, skipna: bool = True, mask=None):
428
428
# doesn't handle ``any`` and ``all`` on
429
429
# object arrays correclty. see
430
430
# https://github.com/numpy/numpy/issues/4352
431
+
432
+ # TODO: Find a less code-smelly way of doing this
431
433
if is_object_dtype (dtype ) and axis is None :
432
- return np .any (values )
434
+ output = values .any ()
435
+ else :
436
+ output = values .any (axis )
437
+
438
+ if isinstance (output , bool ):
439
+ return output
440
+
441
+ # Bruteforce way
442
+ def is_any (values : np .ndarray ) -> bool :
443
+ """
444
+ Check if any elements along an axis evaluate to True.
445
+
446
+ Parameters
447
+ ----------
448
+ values : np.ndarray
449
+ Array to iterate over it's values.
450
+
451
+ Returns
452
+ -------
453
+ bool
454
+ Indicating if any of the values in the array, evaluates to True.
455
+ """
456
+ for value in values .tolist ():
457
+ if bool (value ):
458
+ return True
459
+ return False
433
460
434
- return values . any ( axis )
461
+ return is_any ( values )
435
462
436
463
437
464
def nanall (values , axis = None , skipna : bool = True , mask = None ):
@@ -469,11 +496,37 @@ def nanall(values, axis=None, skipna: bool = True, mask=None):
469
496
# doesn't handle ``any`` and ``all`` on
470
497
# object arrays correclty. see
471
498
# https://github.com/numpy/numpy/issues/4352
472
- if is_object_dtype (dtype ) and axis is None :
473
- return np .all (values )
474
499
475
- return values .all (axis )
500
+ # TODO: Find a less code-smelly way of doing this
501
+ if is_object_dtype (dtype ) and axis is None :
502
+ output = values .all ()
503
+ else :
504
+ output = values .all (axis )
505
+
506
+ if isinstance (output , bool ):
507
+ return output
508
+
509
+ # Bruteforce way
510
+ def is_all (values : np .ndarray ) -> bool :
511
+ """
512
+ Check if all elements along an axis evaluate to True.
513
+
514
+ Parameters
515
+ ----------
516
+ values : np.ndarray
517
+ Array to iterate over it's values.
518
+
519
+ Returns
520
+ -------
521
+ bool
522
+ Indicating if all of the values in the array, evaluates to True.
523
+ """
524
+ for value in values .tolist ():
525
+ if not bool (value ):
526
+ return False
527
+ return True
476
528
529
+ return is_all (values )
477
530
478
531
@disallow ("M8" )
479
532
def nansum (values , axis = None , skipna = True , min_count = 0 , mask = None ):
0 commit comments