Skip to content

REGR: assert_index_equal raising with non matching pd.NA #48608

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 10 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.5.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Fixed regressions

Bug fixes
~~~~~~~~~
-
- Bug in :func:`assert_index_equal` for extension arrays with non matching ``NA`` raising ``ValueError`` (:issue:`48608`)
-

.. ---------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ def _get_ilevel_values(index, level):
if not left.equals(right):
mismatch = left._values != right._values

if is_extension_array_dtype(mismatch):
mismatch = cast("ExtensionArray", mismatch).fillna(True)

diff = np.sum(mismatch.astype(int)) * 100.0 / len(left)
msg = f"{obj} values are different ({np.round(diff, 5)} %)"
raise_assert_detail(obj, msg, left, right)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/util/test_assert_index_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,11 @@ def test_assert_index_equal_object_ints_order_false():
idx1 = Index([1, 3], dtype="object")
idx2 = Index([3, 1], dtype="object")
tm.assert_index_equal(idx1, idx2, check_order=False)


def test_assert_ea_index_equal_non_matching_na():
# GH#48608
idx1 = Index([1, 2], dtype="Int64")
idx2 = Index([1, NA], dtype="Int64")
with pytest.raises(AssertionError, match="50.0 %"):
tm.assert_index_equal(idx1, idx2)