Skip to content

Commit c456969

Browse files
jbrockmendelnickleus27
authored andcommitted
Fix FloatingArray.equals on older numpy (pandas-dev#44432)
1 parent 6d34855 commit c456969

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pandas/core/arrays/masked.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
)
4848
from pandas.core.dtypes.inference import is_array_like
4949
from pandas.core.dtypes.missing import (
50+
array_equivalent,
5051
isna,
5152
notna,
5253
)
@@ -636,11 +637,12 @@ def equals(self, other) -> bool:
636637

637638
# GH#44382 if e.g. self[1] is np.nan and other[1] is pd.NA, we are NOT
638639
# equal.
639-
return np.array_equal(self._mask, other._mask) and np.array_equal(
640-
self._data[~self._mask],
641-
other._data[~other._mask],
642-
equal_nan=True,
643-
)
640+
if not np.array_equal(self._mask, other._mask):
641+
return False
642+
643+
left = self._data[~self._mask]
644+
right = other._data[~other._mask]
645+
return array_equivalent(left, right, dtype_equal=True)
644646

645647
def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
646648
if name in {"any", "all"}:

pandas/core/dtypes/missing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ def array_equivalent(
475475
return np.array_equal(left, right)
476476

477477

478-
def _array_equivalent_float(left, right):
479-
return ((left == right) | (np.isnan(left) & np.isnan(right))).all()
478+
def _array_equivalent_float(left, right) -> bool:
479+
return bool(((left == right) | (np.isnan(left) & np.isnan(right))).all())
480480

481481

482482
def _array_equivalent_datetimelike(left, right):

0 commit comments

Comments
 (0)