|
1 | 1 | import numpy as np
|
2 | 2 | import pytest
|
3 | 3 |
|
| 4 | +import pandas as pd |
4 | 5 | from pandas import Timestamp
|
5 | 6 | import pandas._testing as tm
|
6 | 7 |
|
@@ -175,3 +176,38 @@ def test_numpy_array_equal_copy_flag(other_type, check_same):
|
175 | 176 | tm.assert_numpy_array_equal(a, other, check_same=check_same)
|
176 | 177 | else:
|
177 | 178 | tm.assert_numpy_array_equal(a, other, check_same=check_same)
|
| 179 | + |
| 180 | + |
| 181 | +def test_numpy_array_equal_contains_na(): |
| 182 | + # https://github.com/pandas-dev/pandas/issues/31881 |
| 183 | + a = np.array([True, False]) |
| 184 | + b = np.array([True, pd.NA], dtype=object) |
| 185 | + |
| 186 | + msg = """numpy array are different |
| 187 | +
|
| 188 | +numpy array values are different \\(50.0 %\\) |
| 189 | +\\[left\\]: \\[True, False\\] |
| 190 | +\\[right\\]: \\[True, <NA>\\]""" |
| 191 | + |
| 192 | + with pytest.raises(AssertionError, match=msg): |
| 193 | + tm.assert_numpy_array_equal(a, b) |
| 194 | + |
| 195 | + |
| 196 | +def test_numpy_array_equal_identical_na(nulls_fixture): |
| 197 | + a = np.array([nulls_fixture], dtype=object) |
| 198 | + |
| 199 | + tm.assert_numpy_array_equal(a, a) |
| 200 | + |
| 201 | + |
| 202 | +def test_numpy_array_equal_different_na(): |
| 203 | + a = np.array([np.nan], dtype=object) |
| 204 | + b = np.array([pd.NA], dtype=object) |
| 205 | + |
| 206 | + msg = """numpy array are different |
| 207 | +
|
| 208 | +numpy array values are different \\(100.0 %\\) |
| 209 | +\\[left\\]: \\[nan\\] |
| 210 | +\\[right\\]: \\[<NA>\\]""" |
| 211 | + |
| 212 | + with pytest.raises(AssertionError, match=msg): |
| 213 | + tm.assert_numpy_array_equal(a, b) |
0 commit comments