diff --git a/doc/source/whatsnew/v1.4.3.rst b/doc/source/whatsnew/v1.4.3.rst index ca8b8ca15ec47..ce53d2b1dd04c 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 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/_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..e3461e62b4eda 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -242,3 +242,17 @@ 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) + + +def test_assert_index_equal_object_ints_order_false(): + # GH#47207 + idx1 = Index([1, 3], dtype="object") + idx2 = Index([3, 1], dtype="object") + tm.assert_index_equal(idx1, idx2, check_order=False)