Skip to content

TST/BUG: test unsortable in safe_sort and Categorical (GH13714) #13733

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion ci/requirements-2.7.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
python-dateutil=2.4.1
pytz=2013b
numpy=1.9.3
numpy
cython=0.19.1
2 changes: 1 addition & 1 deletion ci/requirements-2.7.run
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
python-dateutil=2.4.1
pytz=2013b
numpy=1.9.3
numpy
xlwt=0.7.5
numexpr
pytables
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from numpy.random import RandomState
from numpy import nan
import datetime
from distutils.version import LooseVersion

from pandas import Series, Categorical, CategoricalIndex, Index
import pandas as pd
Expand Down Expand Up @@ -116,6 +117,19 @@ def test_mixed_integer(self):
labels = [0, 1, 2, 3, 0, -1, 1]
result, result_labels = algos.safe_sort(values, labels)
expected = np.array([0, 1, 'a', 'b'], dtype=object)
expected_labels = np.array([3, 1, 0, 2, 3, -1, 1])
tm.assert_numpy_array_equal(result, expected)
tm.assert_numpy_array_equal(result_labels, expected_labels)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated. (These three lines where lost in #13514.)


def test_unsortable(self):
# GH 13714
arr = np.array([1, 2, datetime.datetime.now(), 0, 3], dtype=object)
if compat.PY2 and LooseVersion(np.__version__) >= "1.10":
# RuntimeWarning: tp_compare didn't return -1 or -2 for exception
with tm.assert_produces_warning(RuntimeWarning):
tm.assertRaises(TypeError, algos.safe_sort, arr)
else:
tm.assertRaises(TypeError, algos.safe_sort, arr)

def test_exceptions(self):
with tm.assertRaisesRegexp(TypeError,
Expand Down
15 changes: 3 additions & 12 deletions pandas/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,9 @@ def test_constructor_unsortable(self):
factor = Categorical.from_array(arr, ordered=False)
self.assertFalse(factor.ordered)

if compat.PY3:
self.assertRaises(
TypeError, lambda: Categorical.from_array(arr, ordered=True))
else:
# this however will raise as cannot be sorted (on PY3 or older
# numpies)
if LooseVersion(np.__version__) < "1.10":
self.assertRaises(
TypeError,
lambda: Categorical.from_array(arr, ordered=True))
else:
Categorical.from_array(arr, ordered=True)
# this however will raise as cannot be sorted
self.assertRaises(
TypeError, lambda: Categorical.from_array(arr, ordered=True))

def test_is_equal_dtype(self):

Expand Down