Skip to content

Commit ea14a46

Browse files
authored
TST: Fix assert_is_sorted for eas (#55536)
1 parent 5bfb41f commit ea14a46

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pandas/_testing/asserters.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ def assert_is_sorted(seq) -> None:
440440
if isinstance(seq, (Index, Series)):
441441
seq = seq.values
442442
# sorting does not change precisions
443-
assert_numpy_array_equal(seq, np.sort(np.array(seq)))
443+
if isinstance(seq, np.ndarray):
444+
assert_numpy_array_equal(seq, np.sort(np.array(seq)))
445+
else:
446+
assert_extension_array_equal(seq, seq[seq.argsort()])
444447

445448

446449
def assert_categorical_equal(

pandas/tests/util/test_util.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import pytest
44

5-
from pandas import compat
5+
from pandas import (
6+
array,
7+
compat,
8+
)
69
import pandas._testing as tm
710

811

@@ -44,3 +47,12 @@ def test_datapath(datapath):
4447
def test_external_error_raised():
4548
with tm.external_error_raised(TypeError):
4649
raise TypeError("Should not check this error message, so it will pass")
50+
51+
52+
def test_is_sorted():
53+
arr = array([1, 2, 3], dtype="Int64")
54+
tm.assert_is_sorted(arr)
55+
56+
arr = array([4, 2, 3], dtype="Int64")
57+
with pytest.raises(AssertionError, match="ExtensionArray are different"):
58+
tm.assert_is_sorted(arr)

0 commit comments

Comments
 (0)