Skip to content

return type of predicate in select is too strict? #2487

@ghost

Description

is there a reason to be so strict in the predicate return type?
notably python3 is much less cavalier about coercing things to bool.

In [75]: from pandas.util.testing import makeCustomDataframe as mkdf
    ...: mkdf(4,2,r_idx_nlevels=2).select(lambda x: bool(re.search("g1",x[0])))
Out[75]: 
C0              C_l0_g0 C_l0_g1
R0      R1                     
R_l0_g1 R_l1_g1    R1C0    R1C1
In [76]: from pandas.util.testing import makeCustomDataframe as mkdf
    ...: mkdf(4,2,r_idx_nlevels=2).select(lambda x: re.search("g1",x[0]))
    ...: 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-76-c172e2763471> in <module>()
      1 from pandas.util.testing import makeCustomDataframe as mkdf
----> 2 mkdf(4,2,r_idx_nlevels=2).select(lambda x: re.search("g1",x[0]))
      3 

/home/user1/src/pandas/pandas/core/generic.pyc in select(self, crit, axis)
    316 
    317         if len(axis) > 0:
--> 318             new_axis = axis[np.asarray([crit(label) for label in axis])]
    319         else:
    320             new_axis = axis

/home/user1/src/pandas/pandas/core/index.pyc in __getitem__(self, key)
   1727             return tuple(retval)
   1728         else:
-> 1729             if com._is_bool_indexer(key):
   1730                 key = np.asarray(key)
   1731                 sortorder = self.sortorder

/home/user1/src/pandas/pandas/core/common.pyc in _is_bool_indexer(key)
    651         if not lib.is_bool_array(key):
    652             if isnull(key).any():
--> 653                 raise ValueError('cannot index with vector containing '
    654                                  'NA / NaN values')
    655             return False

ValueError: cannot index with vector containing NA / NaN values

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions