diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 0787ec56379b2..925126449eca3 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -21,7 +21,6 @@ npt, type_t, ) -from pandas.compat.numpy import function as nv from pandas.core.dtypes.common import ( is_bool_dtype, @@ -447,144 +446,6 @@ def _values_for_argsort(self) -> np.ndarray: data[self._mask] = -1 return data - def any(self, *, skipna: bool = True, axis: int | None = 0, **kwargs): - """ - Return whether any element is True. - - Returns False unless there is at least one element that is True. - By default, NAs are skipped. If ``skipna=False`` is specified and - missing values are present, similar :ref:`Kleene logic ` - is used as for logical operations. - - Parameters - ---------- - skipna : bool, default True - Exclude NA values. If the entire array is NA and `skipna` is - True, then the result will be False, as for an empty array. - If `skipna` is False, the result will still be True if there is - at least one element that is True, otherwise NA will be returned - if there are NA's present. - axis : int or None, default 0 - **kwargs : any, default None - Additional keywords have no effect but might be accepted for - compatibility with NumPy. - - Returns - ------- - bool or :attr:`pandas.NA` - - See Also - -------- - numpy.any : Numpy version of this method. - BooleanArray.all : Return whether all elements are True. - - Examples - -------- - The result indicates whether any element is True (and by default - skips NAs): - - >>> pd.array([True, False, True]).any() - True - >>> pd.array([True, False, pd.NA]).any() - True - >>> pd.array([False, False, pd.NA]).any() - False - >>> pd.array([], dtype="boolean").any() - False - >>> pd.array([pd.NA], dtype="boolean").any() - False - - With ``skipna=False``, the result can be NA if this is logically - required (whether ``pd.NA`` is True or False influences the result): - - >>> pd.array([True, False, pd.NA]).any(skipna=False) - True - >>> pd.array([False, False, pd.NA]).any(skipna=False) - - """ - kwargs.pop("axis", None) - nv.validate_any((), kwargs) - - values = self._data.copy() - np.putmask(values, self._mask, False) - result = values.any(axis=axis) - - if skipna: - return result - else: - if result or self.size == 0 or not self._mask.any(): - return result - else: - return self.dtype.na_value - - def all(self, *, skipna: bool = True, axis: int | None = 0, **kwargs): - """ - Return whether all elements are True. - - Returns True unless there is at least one element that is False. - By default, NAs are skipped. If ``skipna=False`` is specified and - missing values are present, similar :ref:`Kleene logic ` - is used as for logical operations. - - Parameters - ---------- - skipna : bool, default True - Exclude NA values. If the entire array is NA and `skipna` is - True, then the result will be True, as for an empty array. - If `skipna` is False, the result will still be False if there is - at least one element that is False, otherwise NA will be returned - if there are NA's present. - axis : int or None, default 0 - **kwargs : any, default None - Additional keywords have no effect but might be accepted for - compatibility with NumPy. - - Returns - ------- - bool or :attr:`pandas.NA` - - See Also - -------- - numpy.all : Numpy version of this method. - BooleanArray.any : Return whether any element is True. - - Examples - -------- - The result indicates whether any element is True (and by default - skips NAs): - - >>> pd.array([True, True, pd.NA]).all() - True - >>> pd.array([True, False, pd.NA]).all() - False - >>> pd.array([], dtype="boolean").all() - True - >>> pd.array([pd.NA], dtype="boolean").all() - True - - With ``skipna=False``, the result can be NA if this is logically - required (whether ``pd.NA`` is True or False influences the result): - - >>> pd.array([True, True, pd.NA]).all(skipna=False) - - >>> pd.array([True, False, pd.NA]).all(skipna=False) - False - """ - kwargs.pop("axis", None) - nv.validate_all((), kwargs) - - values = self._data.copy() - np.putmask(values, self._mask, True) - result = values.all(axis=axis) - - if skipna: - return result - else: - if not result or self.size == 0 or not self._mask.any(): - return result - else: - return self.dtype.na_value - def _logical_method(self, other, op): assert op.__name__ in {"or_", "ror_", "and_", "rand_", "xor", "rxor"}