Skip to content

Commit 2a1b2d4

Browse files
committed
fix categorical tests
1 parent f7fb76e commit 2a1b2d4

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

pandas/tests/base/test_unique.py

-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ def test_unique_null(null_obj, index_or_series_obj):
6464
if is_datetime64tz_dtype(obj.dtype):
6565
result = result.normalize()
6666
expected = expected.normalize()
67-
elif isinstance(obj, pd.CategoricalIndex):
68-
expected = expected.set_categories(unique_values_not_null)
6967
tm.assert_index_equal(result, expected)
7068
else:
7169
expected = np.array(unique_values, dtype=obj.dtype)

pandas/tests/indexes/categorical/test_category.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pandas._libs import index as libindex
55

66
import pandas as pd
7-
from pandas import Categorical
7+
from pandas import Categorical, CategoricalDtype
88
import pandas._testing as tm
99
from pandas.core.indexes.api import CategoricalIndex, Index
1010

@@ -306,18 +306,19 @@ def test_drop_duplicates(self, data, categories, expected):
306306
tm.assert_index_equal(result, e)
307307

308308
@pytest.mark.parametrize(
309-
"data, categories, expected_data, expected_categories",
309+
"data, categories, expected_data",
310310
[
311-
([1, 1, 1], [1, 2, 3], [1], [1]),
312-
([1, 1, 1], list("abc"), [np.nan], []),
313-
([1, 2, "a"], [1, 2, 3], [1, 2, np.nan], [1, 2]),
314-
([2, "a", "b"], list("abc"), [np.nan, "a", "b"], ["a", "b"]),
311+
([1, 1, 1], [1, 2, 3], [1]),
312+
([1, 1, 1], list("abc"), [np.nan]),
313+
([1, 2, "a"], [1, 2, 3], [1, 2, np.nan]),
314+
([2, "a", "b"], list("abc"), [np.nan, "a", "b"]),
315315
],
316316
)
317-
def test_unique(self, data, categories, expected_data, expected_categories):
317+
def test_unique(self, data, categories, expected_data, ordered):
318+
dtype = CategoricalDtype(categories, ordered=ordered)
318319

319-
idx = CategoricalIndex(data, categories=categories)
320-
expected = CategoricalIndex(expected_data, categories=expected_categories)
320+
idx = CategoricalIndex(data, dtype=dtype)
321+
expected = CategoricalIndex(expected_data, dtype=dtype)
321322
tm.assert_index_equal(idx.unique(), expected)
322323

323324
def test_repr_roundtrip(self):

pandas/tests/test_algos.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def test_categorical(self):
567567

568568
# we are expecting to return in the order
569569
# of appearance
570-
expected = Categorical(list("bac"), categories=list("bac"))
570+
expected = Categorical(list("bac"))
571571

572572
# we are expecting to return in the order
573573
# of the categories
@@ -597,7 +597,7 @@ def test_categorical(self):
597597
tm.assert_categorical_equal(result, expected)
598598

599599
# CI -> return CI
600-
ci = CategoricalIndex(Categorical(list("baabc"), categories=list("bac")))
600+
ci = CategoricalIndex(Categorical(list("baabc"), categories=list("abc")))
601601
expected = CategoricalIndex(expected)
602602
result = ci.unique()
603603
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)