Skip to content

Commit

Permalink
TST: unicode columns in filter(like=...) #2467
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Dec 10, 2012
1 parent 49c9226 commit aa8025f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pandas 0.10.0
- Preserve time zone when .append-ing two time series (#2260)
- Box timestamps when calling reset_index on time-zone-aware index rather
than creating a tz-less datetime64 column (#2262)
- Enable searching non-string columns in DataFrame.filter(like=...) (#2467)

pandas 0.9.1
============
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2890,7 +2890,9 @@ 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 str(x), axis=1)
matchf = lambda x: (like in x if isinstance(x, basestring)
else like in str(x))
return self.select(matchf, 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 @@ -5900,6 +5900,11 @@ def test_filter(self):
filtered = self.mixed_frame.filter(like='foo')
self.assert_('foo' in filtered)

# unicode columns, won't ascii-encode
df = self.frame.rename(columns={'B': u'\u2202'})
filtered = df.filter(like='C')
self.assertTrue('C' in filtered)

def test_filter_regex_search(self):
fcopy = self.frame.copy()
fcopy['AA'] = 1
Expand Down

0 comments on commit aa8025f

Please sign in to comment.