Skip to content

masking empty DataFrame #10126

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

Closed
kdebrab opened this issue May 13, 2015 · 6 comments
Closed

masking empty DataFrame #10126

kdebrab opened this issue May 13, 2015 · 6 comments
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@kdebrab
Copy link
Contributor

kdebrab commented May 13, 2015

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)
@shoyer shoyer added the Bug label May 13, 2015
@shoyer shoyer added this to the Next Major Release milestone May 13, 2015
@jreback
Copy link
Contributor

jreback commented May 13, 2015

This can be trivial fixed by adding here
if len(key) and not is_bool_dtype(key.value):

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Difficulty Novice labels May 22, 2015
@jreback jreback modified the milestones: 0.17.0, Next Major Release May 22, 2015
rekcahpassyla added a commit to rekcahpassyla/pandas that referenced this issue May 22, 2015
rekcahpassyla added a commit to rekcahpassyla/pandas that referenced this issue May 22, 2015
rekcahpassyla added a commit to rekcahpassyla/pandas that referenced this issue May 22, 2015
rekcahpassyla added a commit to rekcahpassyla/pandas that referenced this issue May 26, 2015
rekcahpassyla added a commit to rekcahpassyla/pandas that referenced this issue May 26, 2015
@jreback jreback modified the milestones: 0.16.2, 0.17.0 Jun 2, 2015
rekcahpassyla added a commit to rekcahpassyla/pandas that referenced this issue Jun 3, 2015
shoyer added a commit that referenced this issue Jun 3, 2015
…oolean

BUG: Raise TypeError only if key DataFrame is not empty #10126
@shoyer
Copy link
Member

shoyer commented Jun 3, 2015

fixed by #10196

@shoyer shoyer closed this as completed Jun 3, 2015
cgevans added a commit to cgevans/pandas that referenced this issue Jun 5, 2015
* https://github.com/pydata/pandas: (26 commits)
  disable some deps on 3.2 build
  Fix meantim typo
  DOC: use current ipython in doc build
  PERF: write basic datetimes faster pandas-dev#10271
  TST: fix for bottleneck >= 1.0 nansum behavior, xref pandas-dev#9422
  add numba example to enhancingperf.rst
  BUG: SparseSeries constructor ignores input data name
  BUG: Raise TypeError only if key DataFrame is not empty pandas-dev#10126
  ENH: groupby.apply for Categorical should preserve categories (closes pandas-dev#10138)
  DOC: add in whatsnew/0.17.0.txt
  DOC: move whatsnew from 0.17.0 -> 0.16.2
  BUG:  Holiday(..) with both offset and observance raises NotImplementedError pandas-dev#10217
  BUG: Index.union cannot handle array-likes
  BUG: SparseSeries.abs() resets name
  BUG: Series arithmetic methods incorrectly hold name
  ENH: Don't infer WOM-5MON if we don't support it (pandas-dev#9425)
  BUG: Series.align resets name when fill_value is specified
  BUG: GroupBy.get_group raises ValueError when group key contains NaT
  Close mysql connection in TestXMySQL to prevent tests freezing
  BUG: plot doesnt default to matplotlib axes.grid setting (pandas-dev#9792)
  ...
yarikoptic added a commit to neurodebian/pandas that referenced this issue Jul 2, 2015
* commit 'v0.16.1-97-gbc7d48f': (56 commits)
  disable some deps on 3.2 build
  Fix meantim typo
  DOC: use current ipython in doc build
  PERF: write basic datetimes faster pandas-dev#10271
  TST: fix for bottleneck >= 1.0 nansum behavior, xref pandas-dev#9422
  add numba example to enhancingperf.rst
  BUG: SparseSeries constructor ignores input data name
  BUG: Raise TypeError only if key DataFrame is not empty pandas-dev#10126
  ENH: groupby.apply for Categorical should preserve categories (closes pandas-dev#10138)
  DOC: add in whatsnew/0.17.0.txt
  DOC: move whatsnew from 0.17.0 -> 0.16.2
  BUG:  Holiday(..) with both offset and observance raises NotImplementedError pandas-dev#10217
  BUG: Index.union cannot handle array-likes
  BUG: SparseSeries.abs() resets name
  BUG: Series arithmetic methods incorrectly hold name
  ENH: Don't infer WOM-5MON if we don't support it (pandas-dev#9425)
  BUG: Series.align resets name when fill_value is specified
  BUG: GroupBy.get_group raises ValueError when group key contains NaT
  Close mysql connection in TestXMySQL to prevent tests freezing
  BUG: plot doesnt default to matplotlib axes.grid setting (pandas-dev#9792)
  ...
@zhaoguixu
Copy link

This issue seems not fixed completely. I still get the same error. I have looked up the code and found that _getitem_frame was not fixed yet.

@jreback
Copy link
Contributor

jreback commented Dec 17, 2015

how so? are u using 0.16.2 at least

@zhaoguixu
Copy link

Yes, I am using the latest version. I have checked code of the master branch. _getitem_frame(here) was not fixed as _setitem_frame.

@jreback
Copy link
Contributor

jreback commented Dec 17, 2015

I think you are right. must have slipped by somehow. can you open a new issues (and xref this one), which a copy-pastable example (you can use the above) one.

pull-requests are welcome as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

4 participants