Skip to content
Closed
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
19 changes: 19 additions & 0 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,25 @@ def assert_series_equal(
index_values=left.index,
obj=str(obj),
)
elif not check_dtype:
left_na = np.asarray(left.isna())
right_na = np.asarray(right.isna())
assert_numpy_array_equal(
left_na, right_na, obj=f"{obj} NA mask", index_values=left.index
)

left_valid = left[~left_na].to_numpy(dtype=object)
right_valid = right[~right_na].to_numpy(dtype=object)

_testing.assert_almost_equal(
left_valid,
right_valid,
check_dtype=False,
rtol=rtol,
atol=atol,
obj=str(obj),
index_values=left.index,
)
else:
_testing.assert_almost_equal(
left._values,
Expand Down
10 changes: 10 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,11 @@ 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