Skip to content

Commit 622297c

Browse files
pijuchajreback
authored andcommitted
TST/BUG: test unsortable in safe_sort and Categorical (GH13714)
- Change test for Categorical.from_array - Add test for safe_sort - Change 2.7 build to latest numpy
1 parent 1ce8f8e commit 622297c

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

ci/requirements-2.7.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
python-dateutil=2.4.1
22
pytz=2013b
3-
numpy=1.9.3
3+
numpy
44
cython=0.19.1

ci/requirements-2.7.run

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
python-dateutil=2.4.1
22
pytz=2013b
3-
numpy=1.9.3
3+
numpy
44
xlwt=0.7.5
55
numexpr
66
pytables

pandas/tests/test_algos.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from numpy.random import RandomState
66
from numpy import nan
77
import datetime
8-
98
from pandas import Series, Categorical, CategoricalIndex, Index
109
import pandas as pd
1110

@@ -116,6 +115,19 @@ def test_mixed_integer(self):
116115
labels = [0, 1, 2, 3, 0, -1, 1]
117116
result, result_labels = algos.safe_sort(values, labels)
118117
expected = np.array([0, 1, 'a', 'b'], dtype=object)
118+
expected_labels = np.array([3, 1, 0, 2, 3, -1, 1])
119+
tm.assert_numpy_array_equal(result, expected)
120+
tm.assert_numpy_array_equal(result_labels, expected_labels)
121+
122+
def test_unsortable(self):
123+
# GH 13714
124+
arr = np.array([1, 2, datetime.datetime.now(), 0, 3], dtype=object)
125+
if compat.PY2 and not pd._np_version_under1p10:
126+
# RuntimeWarning: tp_compare didn't return -1 or -2 for exception
127+
with tm.assert_produces_warning(RuntimeWarning):
128+
tm.assertRaises(TypeError, algos.safe_sort, arr)
129+
else:
130+
tm.assertRaises(TypeError, algos.safe_sort, arr)
119131

120132
def test_exceptions(self):
121133
with tm.assertRaisesRegexp(TypeError,

pandas/tests/test_categorical.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,9 @@ def test_constructor_unsortable(self):
9797
factor = Categorical.from_array(arr, ordered=False)
9898
self.assertFalse(factor.ordered)
9999

100-
if compat.PY3:
101-
self.assertRaises(
102-
TypeError, lambda: Categorical.from_array(arr, ordered=True))
103-
else:
104-
# this however will raise as cannot be sorted (on PY3 or older
105-
# numpies)
106-
if LooseVersion(np.__version__) < "1.10":
107-
self.assertRaises(
108-
TypeError,
109-
lambda: Categorical.from_array(arr, ordered=True))
110-
else:
111-
Categorical.from_array(arr, ordered=True)
100+
# this however will raise as cannot be sorted
101+
self.assertRaises(
102+
TypeError, lambda: Categorical.from_array(arr, ordered=True))
112103

113104
def test_is_equal_dtype(self):
114105

0 commit comments

Comments
 (0)