Skip to content

masking empty DataFrame #10126

Closed
Closed
@kdebrab

Description

@kdebrab

In pandas 0.16.1, I get a ValueError when trying to mask an empty DataFrame:

>>> import pandas as pd
>>> df = pd.DataFrame()
>>> df[df>0]
Traceback (most recent call last):

  File "<ipython-input-3-efe84c9ebabc>", line 1, in <module>
    df[df>0]

  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 1787, in __getitem__
    return self._getitem_frame(key)

  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 1859, in _getitem_frame
    raise ValueError('Must pass DataFrame with boolean values only')

ValueError: Must pass DataFrame with boolean values only

Using 'where' works as expected:

>>> df.where(df>0)
Out[4]: 
Empty DataFrame
Columns: []
Index: []

Also, masking a Series works as expected:

>>> ts = pd.Series()
>>> ts[ts>0]
Out[6]: Series([], dtype: float64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions