Skip to content

Commit

Permalink
BUG: use np.iterable to check for iterable, close #1773
Browse files Browse the repository at this point in the history
  • Loading branch information
lodagro committed Sep 4, 2012
1 parent dbfdb07 commit cfe674e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 6 additions & 7 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2610,16 +2610,15 @@ def duplicated(self, cols=None, take_last=False):
-------
duplicated : Series
"""
if cols is not None:
if isinstance(cols, list):
if cols is None:
values = list(self.values.T)
else:
if np.iterable(cols):
values = [self[x].values for x in cols]
keys = lib.fast_zip_fillna(values)
else:
keys = lib.fast_zip_fillna([self[cols]])
else:
values = list(self.values.T)
keys = lib.fast_zip_fillna(values)
values = [self[cols]]

keys = lib.fast_zip_fillna(values)
duplicated = lib.duplicated(keys, take_last=take_last)
return Series(duplicated, index=self.index)

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3885,11 +3885,13 @@ def test_drop_duplicates(self):
assert_frame_equal(result, expected)

# multi column
result = df.drop_duplicates(['A', 'B'])
expected = df.ix[[0, 1, 2, 3]]
result = df.drop_duplicates(np.array(['A', 'B']))
assert_frame_equal(result, expected)
result = df.drop_duplicates(['A', 'B'])
assert_frame_equal(result, expected)

result = df.drop_duplicates(['A', 'B'], take_last=True)
result = df.drop_duplicates(('A', 'B'), take_last=True)
expected = df.ix[[0, 5, 6, 7]]
assert_frame_equal(result, expected)

Expand Down

0 comments on commit cfe674e

Please sign in to comment.