-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Handle NA in assert_numpy_array_equal #31910
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
Changes from all commits
950e0bf
cd86d6a
8f7e719
5c6a742
d006a56
489ee3d
8d5a49a
6905a59
9c4f3ed
9ee33c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
import pandas as pd | ||
from pandas import Timestamp | ||
import pandas._testing as tm | ||
|
||
|
@@ -175,3 +176,38 @@ def test_numpy_array_equal_copy_flag(other_type, check_same): | |
tm.assert_numpy_array_equal(a, other, check_same=check_same) | ||
else: | ||
tm.assert_numpy_array_equal(a, other, check_same=check_same) | ||
|
||
|
||
def test_numpy_array_equal_contains_na(): | ||
# https://github.com/pandas-dev/pandas/issues/31881 | ||
a = np.array([True, False]) | ||
b = np.array([True, pd.NA], dtype=object) | ||
|
||
msg = """numpy array are different | ||
|
||
numpy array values are different \\(50.0 %\\) | ||
\\[left\\]: \\[True, False\\] | ||
\\[right\\]: \\[True, <NA>\\]""" | ||
|
||
with pytest.raises(AssertionError, match=msg): | ||
tm.assert_numpy_array_equal(a, b) | ||
|
||
|
||
def test_numpy_array_equal_identical_na(nulls_fixture): | ||
a = np.array([nulls_fixture], dtype=object) | ||
|
||
tm.assert_numpy_array_equal(a, a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Different NA-likes are not considered equal? Eg I think for now it would be good to keep those not equal (since they behave differently), but if so, we should best add a test for that as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, those are comparing unequal, will add a test |
||
|
||
|
||
def test_numpy_array_equal_different_na(): | ||
a = np.array([np.nan], dtype=object) | ||
b = np.array([pd.NA], dtype=object) | ||
|
||
msg = """numpy array are different | ||
|
||
numpy array values are different \\(100.0 %\\) | ||
\\[left\\]: \\[nan\\] | ||
\\[right\\]: \\[<NA>\\]""" | ||
|
||
with pytest.raises(AssertionError, match=msg): | ||
tm.assert_numpy_array_equal(a, b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice - can you also add a test using
nulls_fixture
that ensures equality passes?