Skip to content

Commit 003c6ac

Browse files
committed
BUG: Fix filter method so that accepts byte and unicode
1 parent ba0e377 commit 003c6ac

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pandas/core/generic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from pandas.tseries.frequencies import to_offset
5151
from pandas import compat
5252
from pandas.compat.numpy import function as nv
53-
from pandas.compat import (map, zip, lzip, lrange, string_types,
53+
from pandas.compat import (map, zip, lzip, lrange, string_types, to_str,
5454
isidentifier, set_function_name, cPickle as pkl)
5555
from pandas.core.ops import _align_method_FRAME
5656
import pandas.core.nanops as nanops
@@ -3218,14 +3218,14 @@ def filter(self, items=None, like=None, regex=None, axis=None):
32183218
**{name: [r for r in items if r in labels]})
32193219
elif like:
32203220
def f(x):
3221-
if not isinstance(x, string_types):
3222-
x = str(x)
3223-
return like in x
3221+
return like in to_str(x)
32243222
values = labels.map(f)
32253223
return self.loc(axis=axis)[values]
32263224
elif regex:
3225+
def f(x):
3226+
return matcher.search(to_str(x)) is not None
32273227
matcher = re.compile(regex)
3228-
values = labels.map(lambda x: matcher.search(str(x)) is not None)
3228+
values = labels.map(f)
32293229
return self.loc(axis=axis)[values]
32303230
else:
32313231
raise TypeError('Must pass either `items`, `like`, or `regex`')

0 commit comments

Comments
 (0)