Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: DataFrame.filter(like=*) should treat non-string values as strings #2467

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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