Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,31 @@ def assert_series_equal(
index_values=left.index,
obj=str(obj),
)
elif not check_dtype:

left_na = left.isna().to_numpy(dtype=bool, copy=False)
right_na = right.isna().to_numpy(dtype=bool, copy=False)
assert_numpy_array_equal(
left_na, right_na, obj=f"{obj} NA mask", index_values=left.index
)


def _normalize(s):
arr = s.to_numpy(dtype=object)
return [(None if pd.isna(x) else x) for x in arr]

left_norm = _normalize(left)
right_norm = _normalize(right)

_testing.assert_almost_equal(
left_norm,
right_norm,
check_dtype=False,
rtol=rtol,
atol=atol,
obj=str(obj),
index_values=left.index,
)
else:
_testing.assert_almost_equal(
left._values,
Expand Down Expand Up @@ -1488,3 +1513,4 @@ def assert_metadata_equivalent(
assert val is None
else:
assert val == getattr(right, attr, None)

9 changes: 9 additions & 0 deletions pandas/tests/util/test_assert_frame_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd
from pandas import DataFrame
import pandas._testing as tm
from pandas.testing import assert_frame_equal


@pytest.fixture(params=[True, False])
Expand Down Expand Up @@ -399,6 +400,7 @@ def test_assert_frame_equal_set_mismatch():
tm.assert_frame_equal(df1, df2)



def test_datetimelike_compat_deprecated():
# GH#55638
df = DataFrame({"a": [1]})
Expand All @@ -413,3 +415,10 @@ def test_datetimelike_compat_deprecated():
tm.assert_series_equal(df["a"], df["a"], check_datetimelike_compat=True)
with tm.assert_produces_warning(Pandas4Warning, match=msg):
tm.assert_series_equal(df["a"], df["a"], check_datetimelike_compat=False)


def test_assert_frame_equal_na_object_vs_int32_check_dtype_false():

df1 = pd.DataFrame({"x": pd.Series([pd.NA], dtype="Int32")})
df2 = pd.DataFrame({"x": pd.Series([pd.NA], dtype="object")})
assert_frame_equal(df1, df2, check_dtype=False)
Loading