Skip to content

Commit c4e123a

Browse files
committed
FIX: Handle pd.NA values in assert_frame_equal when check_dtype=False (fixes #61473)
1 parent a3d9049 commit c4e123a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/_testing/asserters.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,20 @@ def assert_frame_equal(
13161316
lcol = left._ixs(i, axis=1)
13171317
rcol = right._ixs(i, axis=1)
13181318

1319+
# Fix for issue #61473: Handle pd.NA values when check_dtype=False
1320+
if not check_dtype:
1321+
# Normalize both pd.NA and np.nan to the same representation for comparison
1322+
# This allows comparison between object and Int32 dtypes with pd.NA
1323+
lcol_normalized = lcol.copy()
1324+
rcol_normalized = rcol.copy()
1325+
1326+
# Replace all null values (pd.NA, np.nan) with a consistent representation
1327+
lcol_normalized = lcol_normalized.where(lcol_normalized.notna(), np.nan)
1328+
rcol_normalized = rcol_normalized.where(rcol_normalized.notna(), np.nan)
1329+
1330+
lcol = lcol_normalized
1331+
rcol = rcol_normalized
1332+
13191333
# GH #38183
13201334
# use check_index=False, because we do not want to run
13211335
# assert_index_equal for each column,

0 commit comments

Comments
 (0)