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

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

Closed
ghost opened this issue Dec 11, 2012 · 0 comments
Closed

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

ghost opened this issue Dec 11, 2012 · 0 comments
Milestone

Comments

@ghost
Copy link

ghost commented Dec 11, 2012

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant