Skip to content

Commit a3b6b3d

Browse files
committed
TST: Add test for categorical with str and tuples
The bug is not present any more. closes #21416
1 parent ad3280e commit a3b6b3d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/arrays/categorical/test_constructors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
import pytest
55

6+
from pandas.compat.numpy import _np_version_under1p16
67
from pandas.core.dtypes.common import is_float_dtype, is_integer_dtype
78
from pandas.core.dtypes.dtypes import CategoricalDtype
89

@@ -601,3 +602,14 @@ def test_constructor_imaginary(self):
601602
c1 = Categorical(values)
602603
tm.assert_index_equal(c1.categories, Index(values))
603604
tm.assert_numpy_array_equal(np.array(c1), np.array(values))
605+
606+
def test_constructor_string_and_tuples(self):
607+
# GH 21416
608+
# For NumPy <1.16, np.array(["", ("a",)]) raises
609+
# ValueError: setting an array element with a sequence.
610+
if _np_version_under1p16:
611+
raise pytest.skip("Skipping for NumPy <1.16")
612+
613+
c = pd.Categorical(["c", ("a", "b"), ("b", "a"), "c"])
614+
expected_index = pd.Index([("a", "b"), ("b", "a"), "c"])
615+
assert c.categories.equals(expected_index)

0 commit comments

Comments
 (0)