From 4e98bad2a81d271fce16a690f678731c18a1a241 Mon Sep 17 00:00:00 2001 From: phofl Date: Mon, 13 Jun 2022 09:41:59 +0200 Subject: [PATCH 1/3] REGR: Avoid regression warning with ea dtype and assert_index_equal order False --- doc/source/whatsnew/v1.4.3.rst | 1 + pandas/_testing/asserters.py | 4 ++-- pandas/tests/util/test_assert_index_equal.py | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.4.3.rst b/doc/source/whatsnew/v1.4.3.rst index ca8b8ca15ec47..03b248bd8f4a4 100644 --- a/doc/source/whatsnew/v1.4.3.rst +++ b/doc/source/whatsnew/v1.4.3.rst @@ -24,6 +24,7 @@ Fixed regressions - Fixed regression in :func:`read_csv` with ``index_col=False`` identifying first row as index names when ``header=None`` (:issue:`46955`) - Fixed regression in :meth:`.DataFrameGroupBy.agg` when used with list-likes or dict-likes and ``axis=1`` that would give incorrect results; now raises ``NotImplementedError`` (:issue:`46995`) - Fixed regression in :meth:`DataFrame.resample` and :meth:`DataFrame.rolling` when used with list-likes or dict-likes and ``axis=1`` that would raise an unintuitive error message; now raises ``NotImplementedError`` (:issue:`46904`) +- Fixed regression in :func:`assert_index_equal` when ``check_order=False`` and :class:`Index` has extension dtype (:issue:`47207`) - Fixed regression in :func:`read_excel` returning ints as floats on certain input sheets (:issue:`46988`) - Fixed regression in :meth:`DataFrame.shift` when ``axis`` is ``columns`` and ``fill_value`` is absent, ``freq`` is ignored (:issue:`47039`) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 7170089581f69..2029a7665d57a 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -367,8 +367,8 @@ def _get_ilevel_values(index, level): # If order doesn't matter then sort the index entries if not check_order: - left = Index(safe_sort(left)) - right = Index(safe_sort(right)) + left = Index(safe_sort(left), dtype=left.dtype) + right = Index(safe_sort(right), dtype=right.dtype) # MultiIndex special comparison for little-friendly error messages if left.nlevels > 1: diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index 8211b52fed650..07f20e6ea5d54 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -242,3 +242,10 @@ def test_assert_index_equal_mixed_dtype(): # GH#39168 idx = Index(["foo", "bar", 42]) tm.assert_index_equal(idx, idx, check_order=False) + + +def test_assert_index_equal_ea_dtype_order_false(any_numeric_ea_dtype): + # GH#47207 + idx1 = Index([1, 3], dtype=any_numeric_ea_dtype) + idx2 = Index([3, 1], dtype=any_numeric_ea_dtype) + tm.assert_index_equal(idx1, idx2, check_order=False) From aa6e1656cadc0d5183f1725668b37462710c42a2 Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 14 Jun 2022 08:54:43 +0200 Subject: [PATCH 2/3] Add test --- doc/source/whatsnew/v1.4.3.rst | 2 +- pandas/tests/util/test_assert_index_equal.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.4.3.rst b/doc/source/whatsnew/v1.4.3.rst index 03b248bd8f4a4..ce53d2b1dd04c 100644 --- a/doc/source/whatsnew/v1.4.3.rst +++ b/doc/source/whatsnew/v1.4.3.rst @@ -24,7 +24,7 @@ Fixed regressions - Fixed regression in :func:`read_csv` with ``index_col=False`` identifying first row as index names when ``header=None`` (:issue:`46955`) - Fixed regression in :meth:`.DataFrameGroupBy.agg` when used with list-likes or dict-likes and ``axis=1`` that would give incorrect results; now raises ``NotImplementedError`` (:issue:`46995`) - Fixed regression in :meth:`DataFrame.resample` and :meth:`DataFrame.rolling` when used with list-likes or dict-likes and ``axis=1`` that would raise an unintuitive error message; now raises ``NotImplementedError`` (:issue:`46904`) -- Fixed regression in :func:`assert_index_equal` when ``check_order=False`` and :class:`Index` has extension dtype (:issue:`47207`) +- Fixed regression in :func:`assert_index_equal` when ``check_order=False`` and :class:`Index` has extension or object dtype (:issue:`47207`) - Fixed regression in :func:`read_excel` returning ints as floats on certain input sheets (:issue:`46988`) - Fixed regression in :meth:`DataFrame.shift` when ``axis`` is ``columns`` and ``fill_value`` is absent, ``freq`` is ignored (:issue:`47039`) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index 07f20e6ea5d54..b2e87d04cee98 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -249,3 +249,10 @@ def test_assert_index_equal_ea_dtype_order_false(any_numeric_ea_dtype): idx1 = Index([1, 3], dtype=any_numeric_ea_dtype) idx2 = Index([3, 1], dtype=any_numeric_ea_dtype) tm.assert_index_equal(idx1, idx2, check_order=False) + + +def test_assert_index_equal_object_ints_order_false(any_numeric_ea_dtype): + # GH#47207 + idx1 = Index([1, 3], dtype="object") + idx2 = Index([3, 1], dtype="object") + tm.assert_index_equal(idx1, idx2, check_order=False) From 5879fb422605c01cb0b8b5d3bb638cd83e8f1058 Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 15 Jun 2022 09:31:14 +0200 Subject: [PATCH 3/3] Remove fixture --- pandas/tests/util/test_assert_index_equal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index b2e87d04cee98..e3461e62b4eda 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -251,7 +251,7 @@ def test_assert_index_equal_ea_dtype_order_false(any_numeric_ea_dtype): tm.assert_index_equal(idx1, idx2, check_order=False) -def test_assert_index_equal_object_ints_order_false(any_numeric_ea_dtype): +def test_assert_index_equal_object_ints_order_false(): # GH#47207 idx1 = Index([1, 3], dtype="object") idx2 = Index([3, 1], dtype="object")