Skip to content

Commit 6b8e436

Browse files
mroeschkegfyoung
authored andcommitted
BUG: Allow pd.unique to accept tuple of strings (#17108)
1 parent b03f7e5 commit 6b8e436

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,4 @@ Other
327327
^^^^^
328328
- Bug in :func:`eval` where the ``inplace`` parameter was being incorrectly handled (:issue:`16732`)
329329
- Bug in ``.isin()`` in which checking membership in empty ``Series`` objects raised an error (:issue:`16991`)
330+
- Bug in :func:`unique` where checking a tuple of strings raised a ``TypeError`` (:issue:`17108`)

pandas/core/algorithms.py

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ def _ensure_arraylike(values):
170170
ABCIndexClass, ABCSeries)):
171171
inferred = lib.infer_dtype(values)
172172
if inferred in ['mixed', 'string', 'unicode']:
173+
if isinstance(values, tuple):
174+
values = list(values)
173175
values = lib.list_to_object_array(values)
174176
else:
175177
values = np.asarray(values)

pandas/tests/test_algos.py

+9
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,15 @@ def test_order_of_appearance(self):
415415
expected = pd.Categorical(list('abc'))
416416
tm.assert_categorical_equal(result, expected)
417417

418+
@pytest.mark.parametrize("arg ,expected", [
419+
(('1', '1', '2'), np.array(['1', '2'], dtype=object)),
420+
(('foo',), np.array(['foo'], dtype=object))
421+
])
422+
def test_tuple_with_strings(self, arg, expected):
423+
# see GH 17108
424+
result = pd.unique(arg)
425+
tm.assert_numpy_array_equal(result, expected)
426+
418427

419428
class TestIsin(object):
420429

0 commit comments

Comments
 (0)