Skip to content

filter with like keyword fails when column names contain integers #2464

@aflaxman

Description

@aflaxman

Here is a small example:

In [58]:
df = pd.DataFrame(0., index=[0,1,2], columns=[0,1,'A','B'])
df.filter(like='A')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in ()
      1 # BUG in pandas: cannot filter with like keyword if columns contain integers and string
      2 df = pd.DataFrame(0., index=[0,1,2], columns=[0,1,'A','B'])
----> 3 df.filter(like='A')

/snfs2/HOME/abie/ENV/lib/python2.7/site-packages/pandas-0.10.0.dev_85b4b11-py2.7-linux-x86_64.egg/pandas/core/frame.pyc in filter(self, items, like, regex)
   2864             return self.reindex(columns=[r for r in items if r in self])
   2865         elif like:
-> 2866             return self.select(lambda x: like in x, axis=1)
   2867         elif regex:
   2868             matcher = re.compile(regex)

/snfs2/HOME/abie/ENV/lib/python2.7/site-packages/pandas-0.10.0.dev_85b4b11-py2.7-linux-x86_64.egg/pandas/core/generic.pyc in select(self, crit, axis)
    318 
    319         if len(axis) > 0:
--> 320             new_axis = axis[np.asarray([crit(label) for label in axis])]
    321         else:
    322             new_axis = axis

/snfs2/HOME/abie/ENV/lib/python2.7/site-packages/pandas-0.10.0.dev_85b4b11-py2.7-linux-x86_64.egg/pandas/core/frame.pyc in (x)
   2864             return self.reindex(columns=[r for r in items if r in self])
   2865         elif like:
-> 2866             return self.select(lambda x: like in x, axis=1)
   2867         elif regex:
   2868             matcher = re.compile(regex)

TypeError: argument of type 'int' is not iterable

This may have a simple solution, by making all of the labels into strings on line 320 of generic.py, I will investigate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions