Skip to content

Fix FloatingArray.equals on older numpy #44432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
)
from pandas.core.dtypes.inference import is_array_like
from pandas.core.dtypes.missing import (
array_equivalent,
isna,
notna,
)
Expand Down Expand Up @@ -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"}:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down