Skip to content

BUG: TypeError when trying to set values in empty DataFrame using boolean key #10195

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
rekcahpassyla opened this issue May 22, 2015 · 1 comment

Comments

@rekcahpassyla
Copy link
Contributor

Found this bug through #10188 - it caused build failure

import numpy as np
import pandas as pd

pd.show_versions()

df = pd.DataFrame([[2, 2]], index=pd.DatetimeIndex(['2011-01-01']))
df2 = pd.DataFrame([[1, 1]], index=pd.DatetimeIndex(['2011-01-01']))

df[df > df2] = 47

assert np.all(df.values==47)

df = pd.DataFrame()
df2 = pd.DataFrame()

df[df > df2] = 47

results in this error (in both 0.15.2 and 0.16.1)

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 26 Stepping 5, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.16.1-46-g0aceb38
nose: 1.3.6
Cython: 0.22
numpy: 1.9.2
scipy: 0.14.0
statsmodels: 0.6.1
IPython: 3.1.0
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.4
bottleneck: 0.8.0
tables: 3.1.1
numexpr: 2.3.1
matplotlib: 1.4.3
openpyxl: None
xlrd: 0.9.3
xlwt: None
xlsxwriter: 0.7.2
lxml: 3.4.4
bs4: 4.3.2
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.0.4
pymysql: None
psycopg2: None
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
c:\test_set_empty_frame_with_boolean.py in <module>()
     14 df2 = pd.DataFrame()
     15
---> 16 df[df > df2] = 47
     17

c:\python\envs\pandas-0.16.1\lib\site-packages\pandas\core\frame.pyc in __setitem__(self, key, value)
   2119             self._setitem_array(key, value)
   2120         elif isinstance(key, DataFrame):
-> 2121             self._setitem_frame(key, value)
   2122         else:
   2123             # set column

c:\python\envs\pandas-0.16.1\lib\site-packages\pandas\core\frame.pyc in _setitem_frame(self, key, value)
   2153         # df[df > df2] = 0
   2154         if key.values.dtype != np.bool_:
-> 2155             raise TypeError('Must pass DataFrame with boolean values only')
   2156
   2157         self._check_inplace_setting(value)

TypeError: Must pass DataFrame with boolean values only

Proposed #10196

@jreback
Copy link
Contributor

jreback commented May 22, 2015

this is a dupe of #10126

@jreback jreback closed this as completed May 22, 2015
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

No branches or pull requests

2 participants