-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
Error when updating dataframe with empty filter #9596
Comments
pls show pd.show_versions() this looks like an older fixed bug |
INSTALLED VERSIONScommit: None pandas: 0.15.0 |
I can reproduce the bug: In [51]: pd.show_versions()
INSTALLED VERSIONS
------------------
commit: 3e7f21ceaf9b456ab3e7c2b76166d580e321bed1
python: 2.7.9.final.0
python-bits: 64
OS: Darwin
OS-release: 14.1.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.16.0-110-g3e7f21c
nose: 1.3.6
Cython: 0.22
numpy: 1.9.2
scipy: None
statsmodels: None
IPython: 3.1.0
sphinx: None
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.2
bottleneck: 1.0.0
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.4.3
openpyxl: 2.2.1
xlrd: 0.9.3
xlwt: None
xlsxwriter: 0.7.2
lxml: 3.4.2
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 0.9.9
pymysql: 0.6.6.None
psycopg2: None Here's how I reproduced with python code in ipython notebook: df = pd.DataFrame({'a': ['1', '2', '3'],
'b': ['11', '22', '33'],
'c': ['111', '222', '333']})
print(df.loc[df.b.isnull(), 'a'])
print(df.b)
print('')
new_s = df.loc[df.b.isnull(), 'a']
print(new_s)
new_s = df.b
print(new_s) Output:
Now to show the error: df = pd.DataFrame({'a': ['1', '2', '3'],
'b': ['11', '22', '33'],
'c': ['111', '222', '333']})
print(df.loc[df.b.isnull(), 'a'])
print(df.b)
print('')
df.loc[df.b.isnull(), 'a'] = df.b Output:
I can also verify the other behavior: df = pd.DataFrame({'a': ['1', '2', '3'],
'b': ['11', '22', '33'],
'c': [111, 222, 333]}) # Type changed to int
print(df.loc[df.b.isnull(), 'a'])
print(df.b)
print('')
df.loc[df.b.isnull(), 'a'] = df.b
print('')
new_s = df.loc[df.b.isnull(), 'a']
print(new_s)
new_s = df.b
print(new_s) Output:
|
This bug appears only when I assign |
Something I can't do: pd.Series([], name='a', dtype=object) = df.b Output:
|
I'm going to pass this over. I can't seem to make traction on it. |
Very cool. I never would have found that. |
Thanks for fixing - any idea when the version with the fix (0.16.1?) is going live? |
The filtering condition is always false (b is never null) and the above code produces this error:
Array is not broadcastable to correct shape
.If, however, I change the type for column 'c' - which is not even mentioned in the assignment expression (!) - from str to int,
No errors are produced.
Would be nice to have consistent behaviour and not have any errors - could not find anything in the documentation saying that applying .loc on empty filter is considered illegal?
The text was updated successfully, but these errors were encountered: