Skip to content

Commit 6dadb83

Browse files
committed
TST: Add unit test for assert_frame_equal fix (GH#61473)
1 parent c4e123a commit 6dadb83

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/util/test_assert_frame_equal.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pandas as pd
44
from pandas import DataFrame
55
import pandas._testing as tm
6+
import numpy as np
67

78

89
@pytest.fixture(params=[True, False])
@@ -395,3 +396,23 @@ def test_assert_frame_equal_set_mismatch():
395396
msg = r'DataFrame.iloc\[:, 0\] \(column name="set_column"\) values are different'
396397
with pytest.raises(AssertionError, match=msg):
397398
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

Comments
 (0)