-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Unexpected result when setting a row by a dict #16724
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
Comments
Hmm, all our setting code deals with iterables, which means the I'll let Jeff weigh in, but I don't think we'll want to support this. If you want that behavior, you'll need to pass the dictionary to a |
Thanks for your reply. I think if this will not be supported, I think the example in the document should be removed for reducing confusion.😅 |
Your example probably should work then, my mistake. It seems like we don't probably set when there are multiple dtypes? # two dtypes
In [44]: x = pd.DataFrame({'x': [1, 2, 3], 'y': ['3', '4', '5']})
In [46]: x.iloc[1] = {'x': 9, 'y': '99'}
In [47]: x # set incorrectly with the keys
Out[47]:
x y
0 1 3
1 x y
2 3 5
# single dtype
In [48]: x = pd.DataFrame({'x': [1, 2, 3], 'y': [3, 4, 5]})
In [49]: x.iloc[1] = {'x': 9, 'y': 99}
In [50]: x # sets correctly
Out[50]:
x y
0 1 3
1 9 99
2 3 5 |
Probably. :-) |
The ability to do this is certainly deliberate (I mean assigning with a dict, not the fact that it uses the keys instead of values), although I am not sure I am too happy about that :-) (way too many corner cases that come up by allowing this, eg #10219) I thought there has been some related discussion about this recently, but only find #16309, (side note: it's would maybe be worth opening a discussion whether we would want to deprecate this?) |
I don't think this is inconsistent with setting with a |
|
This fails since dict is considered a list-like and the reported cases is handled under the assumption that it's a list, here. I find the I found some discussions here but couldn't crack it yet. |
Duplicate report: #29917 |
This looks to work on master. Could use a test
|
Looks like there's a test for this issue: |
Code Sample, a copy-pastable example if possible
Problem description
Have no idea why the keys are set to the rows.
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Darwin
OS-release: 16.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.20.1
pytest: 3.0.7
pip: 9.0.1
setuptools: 35.0.2
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: 0.9.5
IPython: 6.0.0
sphinx: 1.5.5
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: 3.7.3
bs4: 4.6.0
html5lib: 0.999999999
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: