From c8c95e232c22464b21607268ef65e564024755f5 Mon Sep 17 00:00:00 2001 From: phofl Date: Sun, 23 Jan 2022 04:18:32 +0100 Subject: [PATCH 1/3] REGR: check_flags not respected in assert_frame_equal --- doc/source/whatsnew/v1.4.1.rst | 2 +- pandas/_testing/asserters.py | 1 + pandas/tests/util/test_assert_frame_equal.py | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index 48b62637c26b1..fefd4a0dd56df 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -15,7 +15,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ - Regression in :meth:`Series.mask` with ``inplace=True`` and ``PeriodDtype`` and an incompatible ``other`` coercing to a common dtype instead of raising (:issue:`45546`) -- +- Regression in :func:`.assert_frame_equal` not respecting ``check_flags=False``(:issue:`45554`) .. --------------------------------------------------------------------------- diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 84360403fe9c8..f10609796a730 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -1344,6 +1344,7 @@ def assert_frame_equal( rtol=rtol, atol=atol, check_index=False, + check_flags=check_flags, ) diff --git a/pandas/tests/util/test_assert_frame_equal.py b/pandas/tests/util/test_assert_frame_equal.py index faea0a54dc330..6ff1a1c17b179 100644 --- a/pandas/tests/util/test_assert_frame_equal.py +++ b/pandas/tests/util/test_assert_frame_equal.py @@ -323,9 +323,22 @@ def test_frame_equal_mixed_dtypes(frame_or_series, any_numeric_ea_dtype, indexer tm.assert_equal(obj1, obj2, check_exact=True, check_dtype=False) -def test_assert_series_equal_check_like_different_indexes(): +def test_assert_frame_equal_check_like_different_indexes(): # GH#39739 df1 = DataFrame(index=pd.Index([], dtype="object")) df2 = DataFrame(index=pd.RangeIndex(start=0, stop=0, step=1)) with pytest.raises(AssertionError, match="DataFrame.index are different"): tm.assert_frame_equal(df1, df2, check_like=True) + + +def test_assert_frame_equal_checking_allow_dups_flag(): + # GH#45554 + left = DataFrame([[1, 2], [3, 4]]) + left.flags.allows_duplicate_labels = False + + right = DataFrame([[1, 2], [3, 4]]) + right.flags.allows_duplicate_labels = True + tm.assert_frame_equal(left, right, check_flags=False) + + with pytest.raises(AssertionError, match="allows_duplicate_labels"): + tm.assert_frame_equal(left, right, check_flags=True) From a45dbce8f0b4264d3dd40790157b1fb926cd0850 Mon Sep 17 00:00:00 2001 From: phofl Date: Sun, 23 Jan 2022 19:35:32 +0100 Subject: [PATCH 2/3] Check passed kwarg --- pandas/_testing/asserters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index f10609796a730..d850dcdb1f458 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -1344,7 +1344,7 @@ def assert_frame_equal( rtol=rtol, atol=atol, check_index=False, - check_flags=check_flags, + check_flags=False, ) From 271c674e69542e0b70e3ae1958b29b382e39c1f0 Mon Sep 17 00:00:00 2001 From: phofl Date: Sun, 23 Jan 2022 20:34:32 +0100 Subject: [PATCH 3/3] Fix comment --- doc/source/whatsnew/v1.4.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index fefd4a0dd56df..b6e4609c3458e 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -15,7 +15,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ - Regression in :meth:`Series.mask` with ``inplace=True`` and ``PeriodDtype`` and an incompatible ``other`` coercing to a common dtype instead of raising (:issue:`45546`) -- Regression in :func:`.assert_frame_equal` not respecting ``check_flags=False``(:issue:`45554`) +- Regression in :func:`.assert_frame_equal` not respecting ``check_flags=False`` (:issue:`45554`) .. ---------------------------------------------------------------------------