Skip to content

Commit 94cefbf

Browse files
committed
BUG: normalize pd.NA and np.nan when check_dtype=False (GH#61473)
1 parent 904f3cc commit 94cefbf

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

pandas/_testing/asserters.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,32 +1106,30 @@ def assert_series_equal(
11061106
obj=str(obj),
11071107
)
11081108
elif not check_dtype:
1109-
1109+
11101110
left_na = left.isna().to_numpy(dtype=bool, copy=False)
11111111
right_na = right.isna().to_numpy(dtype=bool, copy=False)
11121112
assert_numpy_array_equal(
11131113
left_na, right_na, obj=f"{obj} NA mask", index_values=left.index
1114-
)
1114+
)
11151115

1116-
1117-
def _normalize(arr):
1118-
1119-
return [
1120-
(None if pd.isna(x) else x)
1121-
for x in arr.to_numpy(dtype=object)
1122-
]
1123-
left_valid = _normalize(left[~left_na])
1124-
right_valid = _normalize(right[~right_na])
1116+
1117+
def _normalize(s):
1118+
arr = s.to_numpy(dtype=object)
1119+
return [(None if pd.isna(x) else x) for x in arr]
1120+
1121+
left_norm = _normalize(left)
1122+
right_norm = _normalize(right)
11251123

11261124
_testing.assert_almost_equal(
1127-
left_valid,
1128-
right_valid,
1129-
check_dtype=False,
1130-
rtol=rtol,
1131-
atol=atol,
1132-
obj=str(obj),
1133-
index_values=left.index,
1134-
)
1125+
left_norm,
1126+
right_norm,
1127+
check_dtype=False,
1128+
rtol=rtol,
1129+
atol=atol,
1130+
obj=str(obj),
1131+
index_values=left.index,
1132+
)
11351133
else:
11361134
_testing.assert_almost_equal(
11371135
left._values,

0 commit comments

Comments
 (0)