Skip to content

Commit

Permalink
BUG: Fixed pd.unique on array of tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed May 30, 2017
1 parent e60dc4c commit 35da5b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.2.txt
Expand Up @@ -39,7 +39,7 @@ Bug Fixes

- Bug in using ``pathlib.Path`` or ``py.path.local`` objects with io functions (:issue:`16291`)
- Bug in ``DataFrame.update()`` with ``overwrite=False`` and ``NaN values`` (:issue:`15593`)

- Bug in :func:`pd.unique` on an array of tuples (:issue:`16519`)


- Fixed a compatibility issue with IPython 6.0's tab completion showing deprecation warnings on Categoricals (:issue:`16409`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Expand Up @@ -163,7 +163,7 @@ def _ensure_arraylike(values):
ABCIndexClass, ABCSeries)):
inferred = lib.infer_dtype(values)
if inferred in ['mixed', 'string', 'unicode']:
values = np.asarray(values, dtype=object)
values = lib.list_to_object_array(values)
else:
values = np.asarray(values)
return values
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/test_algos.py
Expand Up @@ -929,6 +929,22 @@ def test_unique_index(self):
tm.assert_numpy_array_equal(case.duplicated(),
np.array([False, False, False]))

@pytest.mark.parametrize('arr, unique', [
([(0, 0), (0, 1), (1, 0), (1, 1), (0, 0), (0, 1), (1, 0), (1, 1)],
[(0, 0), (0, 1), (1, 0), (1, 1)]),
([('b', 'c'), ('a', 'b'), ('a', 'b'), ('b', 'c')],
[('b', 'c'), ('a', 'b')]),
([('a', 1), ('b', 2), ('a', 3), ('a', 1)],
[('a', 1), ('b', 2), ('a', 3)]),
])
def test_unique_tuples(self, arr, unique):
# https://github.com/pandas-dev/pandas/issues/16519
expected = np.empty(len(unique), dtype=object)
expected[:] = unique

result = pd.unique(arr)
tm.assert_numpy_array_equal(result, expected)


class GroupVarTestMixin(object):

Expand Down

0 comments on commit 35da5b9

Please sign in to comment.