Skip to content

Commit d268359

Browse files
Backport PR #47325 on branch 1.4.x (REGR: Avoid regression warning with ea dtype and assert_index_equal order False) (#47366)
Backport PR #47325: REGR: Avoid regression warning with ea dtype and assert_index_equal order False Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 5a9a9b1 commit d268359

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/source/whatsnew/v1.4.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Fixed regressions
2525
- Fixed regression in :func:`read_csv` with ``index_col=False`` identifying first row as index names when ``header=None`` (:issue:`46955`)
2626
- 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`)
2727
- 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`)
28+
- Fixed regression in :func:`assert_index_equal` when ``check_order=False`` and :class:`Index` has extension or object dtype (:issue:`47207`)
2829
- Fixed regression in :func:`read_excel` returning ints as floats on certain input sheets (:issue:`46988`)
2930
- Fixed regression in :meth:`DataFrame.shift` when ``axis`` is ``columns`` and ``fill_value`` is absent, ``freq`` is ignored (:issue:`47039`)
3031

pandas/_testing/asserters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ def _get_ilevel_values(index, level):
374374

375375
# If order doesn't matter then sort the index entries
376376
if not check_order:
377-
left = Index(safe_sort(left))
378-
right = Index(safe_sort(right))
377+
left = Index(safe_sort(left), dtype=left.dtype)
378+
right = Index(safe_sort(right), dtype=right.dtype)
379379

380380
# MultiIndex special comparison for little-friendly error messages
381381
if left.nlevels > 1:

pandas/tests/util/test_assert_index_equal.py

+14
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,17 @@ def test_assert_index_equal_mixed_dtype():
242242
# GH#39168
243243
idx = Index(["foo", "bar", 42])
244244
tm.assert_index_equal(idx, idx, check_order=False)
245+
246+
247+
def test_assert_index_equal_ea_dtype_order_false(any_numeric_ea_dtype):
248+
# GH#47207
249+
idx1 = Index([1, 3], dtype=any_numeric_ea_dtype)
250+
idx2 = Index([3, 1], dtype=any_numeric_ea_dtype)
251+
tm.assert_index_equal(idx1, idx2, check_order=False)
252+
253+
254+
def test_assert_index_equal_object_ints_order_false():
255+
# GH#47207
256+
idx1 = Index([1, 3], dtype="object")
257+
idx2 = Index([3, 1], dtype="object")
258+
tm.assert_index_equal(idx1, idx2, check_order=False)

0 commit comments

Comments
 (0)