Skip to content

TST: Fix assert_is_sorted for eas #55536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ def assert_is_sorted(seq) -> None:
if isinstance(seq, (Index, Series)):
seq = seq.values
# sorting does not change precisions
assert_numpy_array_equal(seq, np.sort(np.array(seq)))
if isinstance(seq, np.ndarray):
assert_numpy_array_equal(seq, np.sort(np.array(seq)))
else:
assert_extension_array_equal(seq, seq[seq.argsort()])


def assert_categorical_equal(
Expand Down
14 changes: 13 additions & 1 deletion pandas/tests/util/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import pytest

from pandas import compat
from pandas import (
array,
compat,
)
import pandas._testing as tm


Expand Down Expand Up @@ -44,3 +47,12 @@ def test_datapath(datapath):
def test_external_error_raised():
with tm.external_error_raised(TypeError):
raise TypeError("Should not check this error message, so it will pass")


def test_is_sorted():
arr = array([1, 2, 3], dtype="Int64")
tm.assert_is_sorted(arr)

arr = array([4, 2, 3], dtype="Int64")
with pytest.raises(AssertionError, match="ExtensionArray are different"):
tm.assert_is_sorted(arr)