Skip to content

Commit

Permalink
BUG: Allow pd.unique to accept tuple of strings (#17108)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored and gfyoung committed Jul 30, 2017
1 parent b03f7e5 commit 6b8e436
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,4 @@ Other
^^^^^
- Bug in :func:`eval` where the ``inplace`` parameter was being incorrectly handled (:issue:`16732`)
- Bug in ``.isin()`` in which checking membership in empty ``Series`` objects raised an error (:issue:`16991`)
- Bug in :func:`unique` where checking a tuple of strings raised a ``TypeError`` (:issue:`17108`)
2 changes: 2 additions & 0 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def _ensure_arraylike(values):
ABCIndexClass, ABCSeries)):
inferred = lib.infer_dtype(values)
if inferred in ['mixed', 'string', 'unicode']:
if isinstance(values, tuple):
values = list(values)
values = lib.list_to_object_array(values)
else:
values = np.asarray(values)
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ def test_order_of_appearance(self):
expected = pd.Categorical(list('abc'))
tm.assert_categorical_equal(result, expected)

@pytest.mark.parametrize("arg ,expected", [
(('1', '1', '2'), np.array(['1', '2'], dtype=object)),
(('foo',), np.array(['foo'], dtype=object))
])
def test_tuple_with_strings(self, arg, expected):
# see GH 17108
result = pd.unique(arg)
tm.assert_numpy_array_equal(result, expected)


class TestIsin(object):

Expand Down

0 comments on commit 6b8e436

Please sign in to comment.