diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 1797f1aff4235..568f3484e78e4 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -47,6 +47,7 @@ ) from pandas.core.dtypes.inference import is_array_like from pandas.core.dtypes.missing import ( + array_equivalent, isna, notna, ) @@ -636,11 +637,12 @@ def equals(self, other) -> bool: # GH#44382 if e.g. self[1] is np.nan and other[1] is pd.NA, we are NOT # equal. - return np.array_equal(self._mask, other._mask) and np.array_equal( - self._data[~self._mask], - other._data[~other._mask], - equal_nan=True, - ) + if not np.array_equal(self._mask, other._mask): + return False + + left = self._data[~self._mask] + right = other._data[~other._mask] + return array_equivalent(left, right, dtype_equal=True) def _reduce(self, name: str, *, skipna: bool = True, **kwargs): if name in {"any", "all"}: diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index c457b52cf4b0e..eea3fa37b7435 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -475,8 +475,8 @@ def array_equivalent( return np.array_equal(left, right) -def _array_equivalent_float(left, right): - return ((left == right) | (np.isnan(left) & np.isnan(right))).all() +def _array_equivalent_float(left, right) -> bool: + return bool(((left == right) | (np.isnan(left) & np.isnan(right))).all()) def _array_equivalent_datetimelike(left, right):