Skip to content

better err msg for failed boolean slicing of dataframe #859

@adamklein

Description

@adamklein

In [57]: df = DataFrame(np.random.rand(5,5))

In [58]: df[df > 0.5]
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid

The error message is: ('EOF in multi-line statement', (63, 0))

KeyError Traceback (most recent call last)
/Volumes/HD2/adam/Documents/Code/python/rapidquant/ in ()
----> 1 df[df > 0.5]

/Volumes/HD2/adam/Documents/Code/python/pandas/pandas/core/frame.pyc in getitem(self, key)
1419 return self._getitem_multilevel(key)
1420 else:
-> 1421 return self._get_item_cache(key)
1422
1423 def _getitem_array(self, key):

/Volumes/HD2/adam/Documents/Code/python/pandas/pandas/core/generic.pyc in _get_item_cache(self, item)
280 return cache[item]
281 except Exception:
--> 282 values = self._data.get(item)
283 res = self._box_item_values(item, values)
284 cache[item] = res

/Volumes/HD2/adam/Documents/Code/python/pandas/pandas/core/internals.pyc in get(self, item)
612
613 def get(self, item):
--> 614 _, block = self._find_block(item)
615 return block.get(item)
616

/Volumes/HD2/adam/Documents/Code/python/pandas/pandas/core/internals.pyc in _find_block(self, item)
702
703 def _find_block(self, item):
--> 704 self._check_have(item)
705 for i, block in enumerate(self.blocks):
706 if item in block:

/Volumes/HD2/adam/Documents/Code/python/pandas/pandas/core/internals.pyc in _check_have(self, item)
709 def _check_have(self, item):
710 if item not in self.items:
--> 711 raise KeyError('no item named %s' % str(item))
712
713 def reindex_axis(self, new_axis, method=None, axis=0, copy=True):

KeyError: 'no item named 0 1 2 3 4\n0 False True False True False\n1 True True False True True\n2 True True True True False\n3 False True False False True\n4 False True False False True'

And then, this actually silently fails:

df.ix[df > 0.5]

Ie, it returns the wrong data

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