Skip to content

Commit

Permalink
BUG: DataFrame.filter(like=*) should treat non-string values as strin…
Browse files Browse the repository at this point in the history
…gs (issue pandas-dev#2464)
  • Loading branch information
aflaxman committed Dec 9, 2012
1 parent 6c6f154 commit 73beb87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Expand Up @@ -2886,7 +2886,7 @@ def filter(self, items=None, like=None, regex=None):
if items is not None:
return self.reindex(columns=[r for r in items if r in self])
elif like:
return self.select(lambda x: like in x, axis=1)
return self.select(lambda x: like in str(x), axis=1)
elif regex:
matcher = re.compile(regex)
return self.select(lambda x: matcher.search(x) is not None, axis=1)
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_frame.py
Expand Up @@ -5888,6 +5888,11 @@ def test_filter(self):
self.assertEqual(len(filtered.columns), 2)
self.assert_('AA' in filtered)

# like with ints in column names
df = DataFrame(0., index=[0,1,2], columns=[0,1,'_A','_B'])
filtered = df.filter(like='_')
self.assertEqual(len(filtered.columns), 2)

# pass in None
self.assertRaises(Exception, self.frame.filter, items=None)

Expand Down

0 comments on commit 73beb87

Please sign in to comment.