|
3 | 3 | import pandas as pd
|
4 | 4 | from pandas import DataFrame
|
5 | 5 | import pandas._testing as tm
|
| 6 | +import numpy as np |
6 | 7 |
|
7 | 8 |
|
8 | 9 | @pytest.fixture(params=[True, False])
|
@@ -395,3 +396,23 @@ def test_assert_frame_equal_set_mismatch():
|
395 | 396 | msg = r'DataFrame.iloc\[:, 0\] \(column name="set_column"\) values are different'
|
396 | 397 | with pytest.raises(AssertionError, match=msg):
|
397 | 398 | tm.assert_frame_equal(df1, df2)
|
| 399 | + |
| 400 | + |
| 401 | +def test_assert_frame_equal_na_dtype_mismatch(): |
| 402 | + # GH#61473 - Test that pd.NA values are handled correctly when check_dtype=False |
| 403 | + df1 = DataFrame({"a": [pd.NA, 1, 2]}, dtype="Int64") |
| 404 | + df2 = DataFrame({"a": [np.nan, 1, 2]}, dtype="float64") |
| 405 | + |
| 406 | + # This should pass with our fix |
| 407 | + tm.assert_frame_equal(df1, df2, check_dtype=False) |
| 408 | + |
| 409 | + # This should still fail when check_dtype=True |
| 410 | + msg = ( |
| 411 | + "Attributes of DataFrame\\.iloc\\[:, 0\\] " |
| 412 | + '\\(column name="a"\\) are different\n\n' |
| 413 | + 'Attribute "dtype" are different\n' |
| 414 | + "\\[left\\]: Int64\n" |
| 415 | + "\\[right\\]: float64" |
| 416 | + ) |
| 417 | + with pytest.raises(AssertionError, match=msg): |
| 418 | + tm.assert_frame_equal(df1, df2, check_dtype=True) |
0 commit comments