|
20 | 20 | npt,
|
21 | 21 | type_t,
|
22 | 22 | )
|
23 |
| -from pandas.compat.numpy import function as nv |
24 | 23 |
|
25 | 24 | from pandas.core.dtypes.common import (
|
26 | 25 | is_bool_dtype,
|
@@ -445,144 +444,6 @@ def _values_for_argsort(self) -> np.ndarray:
|
445 | 444 | data[self._mask] = -1
|
446 | 445 | return data
|
447 | 446 |
|
448 |
| - def any(self, *, skipna: bool = True, axis: int | None = 0, **kwargs): |
449 |
| - """ |
450 |
| - Return whether any element is True. |
451 |
| -
|
452 |
| - Returns False unless there is at least one element that is True. |
453 |
| - By default, NAs are skipped. If ``skipna=False`` is specified and |
454 |
| - missing values are present, similar :ref:`Kleene logic <boolean.kleene>` |
455 |
| - is used as for logical operations. |
456 |
| -
|
457 |
| - Parameters |
458 |
| - ---------- |
459 |
| - skipna : bool, default True |
460 |
| - Exclude NA values. If the entire array is NA and `skipna` is |
461 |
| - True, then the result will be False, as for an empty array. |
462 |
| - If `skipna` is False, the result will still be True if there is |
463 |
| - at least one element that is True, otherwise NA will be returned |
464 |
| - if there are NA's present. |
465 |
| - axis : int or None, default 0 |
466 |
| - **kwargs : any, default None |
467 |
| - Additional keywords have no effect but might be accepted for |
468 |
| - compatibility with NumPy. |
469 |
| -
|
470 |
| - Returns |
471 |
| - ------- |
472 |
| - bool or :attr:`pandas.NA` |
473 |
| -
|
474 |
| - See Also |
475 |
| - -------- |
476 |
| - numpy.any : Numpy version of this method. |
477 |
| - BooleanArray.all : Return whether all elements are True. |
478 |
| -
|
479 |
| - Examples |
480 |
| - -------- |
481 |
| - The result indicates whether any element is True (and by default |
482 |
| - skips NAs): |
483 |
| -
|
484 |
| - >>> pd.array([True, False, True]).any() |
485 |
| - True |
486 |
| - >>> pd.array([True, False, pd.NA]).any() |
487 |
| - True |
488 |
| - >>> pd.array([False, False, pd.NA]).any() |
489 |
| - False |
490 |
| - >>> pd.array([], dtype="boolean").any() |
491 |
| - False |
492 |
| - >>> pd.array([pd.NA], dtype="boolean").any() |
493 |
| - False |
494 |
| -
|
495 |
| - With ``skipna=False``, the result can be NA if this is logically |
496 |
| - required (whether ``pd.NA`` is True or False influences the result): |
497 |
| -
|
498 |
| - >>> pd.array([True, False, pd.NA]).any(skipna=False) |
499 |
| - True |
500 |
| - >>> pd.array([False, False, pd.NA]).any(skipna=False) |
501 |
| - <NA> |
502 |
| - """ |
503 |
| - kwargs.pop("axis", None) |
504 |
| - nv.validate_any((), kwargs) |
505 |
| - |
506 |
| - values = self._data.copy() |
507 |
| - np.putmask(values, self._mask, False) |
508 |
| - result = values.any(axis=axis) |
509 |
| - |
510 |
| - if skipna: |
511 |
| - return result |
512 |
| - else: |
513 |
| - if result or self.size == 0 or not self._mask.any(): |
514 |
| - return result |
515 |
| - else: |
516 |
| - return self.dtype.na_value |
517 |
| - |
518 |
| - def all(self, *, skipna: bool = True, axis: int | None = 0, **kwargs): |
519 |
| - """ |
520 |
| - Return whether all elements are True. |
521 |
| -
|
522 |
| - Returns True unless there is at least one element that is False. |
523 |
| - By default, NAs are skipped. If ``skipna=False`` is specified and |
524 |
| - missing values are present, similar :ref:`Kleene logic <boolean.kleene>` |
525 |
| - is used as for logical operations. |
526 |
| -
|
527 |
| - Parameters |
528 |
| - ---------- |
529 |
| - skipna : bool, default True |
530 |
| - Exclude NA values. If the entire array is NA and `skipna` is |
531 |
| - True, then the result will be True, as for an empty array. |
532 |
| - If `skipna` is False, the result will still be False if there is |
533 |
| - at least one element that is False, otherwise NA will be returned |
534 |
| - if there are NA's present. |
535 |
| - axis : int or None, default 0 |
536 |
| - **kwargs : any, default None |
537 |
| - Additional keywords have no effect but might be accepted for |
538 |
| - compatibility with NumPy. |
539 |
| -
|
540 |
| - Returns |
541 |
| - ------- |
542 |
| - bool or :attr:`pandas.NA` |
543 |
| -
|
544 |
| - See Also |
545 |
| - -------- |
546 |
| - numpy.all : Numpy version of this method. |
547 |
| - BooleanArray.any : Return whether any element is True. |
548 |
| -
|
549 |
| - Examples |
550 |
| - -------- |
551 |
| - The result indicates whether any element is True (and by default |
552 |
| - skips NAs): |
553 |
| -
|
554 |
| - >>> pd.array([True, True, pd.NA]).all() |
555 |
| - True |
556 |
| - >>> pd.array([True, False, pd.NA]).all() |
557 |
| - False |
558 |
| - >>> pd.array([], dtype="boolean").all() |
559 |
| - True |
560 |
| - >>> pd.array([pd.NA], dtype="boolean").all() |
561 |
| - True |
562 |
| -
|
563 |
| - With ``skipna=False``, the result can be NA if this is logically |
564 |
| - required (whether ``pd.NA`` is True or False influences the result): |
565 |
| -
|
566 |
| - >>> pd.array([True, True, pd.NA]).all(skipna=False) |
567 |
| - <NA> |
568 |
| - >>> pd.array([True, False, pd.NA]).all(skipna=False) |
569 |
| - False |
570 |
| - """ |
571 |
| - kwargs.pop("axis", None) |
572 |
| - nv.validate_all((), kwargs) |
573 |
| - |
574 |
| - values = self._data.copy() |
575 |
| - np.putmask(values, self._mask, True) |
576 |
| - result = values.all(axis=axis) |
577 |
| - |
578 |
| - if skipna: |
579 |
| - return result |
580 |
| - else: |
581 |
| - if not result or self.size == 0 or not self._mask.any(): |
582 |
| - return result |
583 |
| - else: |
584 |
| - return self.dtype.na_value |
585 |
| - |
586 | 447 | def _logical_method(self, other, op):
|
587 | 448 |
|
588 | 449 | assert op.__name__ in {"or_", "ror_", "and_", "rand_", "xor", "rxor"}
|
|
0 commit comments