From cfe674ec635e175d268b08f8feb2a14c25f8f05c Mon Sep 17 00:00:00 2001 From: Wouter Overmeire Date: Tue, 4 Sep 2012 22:26:41 +0200 Subject: [PATCH] BUG: use np.iterable to check for iterable, close #1773 --- pandas/core/frame.py | 13 ++++++------- pandas/tests/test_frame.py | 6 ++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index dc2648a11b134..2d18bdd88a1a3 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 95cd3b451be43..8061fb30fa21a 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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)