Skip to content

Inconsistent dtype changes between multi-column assignment and single-column assignment #27583

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
howsiwei opened this issue Jul 25, 2019 · 3 comments · Fixed by #47323
Closed
Assignees
Labels
Dtype Conversions Unexpected or buggy dtype conversions good first issue Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions

Comments

@howsiwei
Copy link
Contributor

howsiwei commented Jul 25, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame({'a': [0.0], 'b': 0.0})

df[['a', 'b']] = 0
print(df)
print()

df['b'] = 0
print(df)

Output:

     a    b
0  0.0  0.0

     a  b
0  0.0  0

Problem description

As you can see above, the column type doesn't change in multi-column assignment but changes from float64 to int64 in single-column assignment. This behavior seems quite inconsistent.

Expected Output

   a  b
0  0  0

   a  b
0  0  0

Both multi-column assignment and single-column assignment should result in the correct dtype.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 3b96ada
python : 3.6.8.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-52-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.utf8
LOCALE : en_US.UTF-8

pandas : 0.25.0rc0+131.g3b96ada3a
numpy : 1.16.3
pytz : 2019.1
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.0.1
Cython : 0.29.7
pytest : 4.4.2
hypothesis : 4.17.2
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@WillAyd WillAyd added the Indexing Related to indexing on series/frames, not to indexes themselves label Jul 25, 2019
@WillAyd
Copy link
Member

WillAyd commented Jul 25, 2019

Hmm yea looks strange. If you have a PR to fix I think would welcome

@WillAyd WillAyd added the Dtype Conversions Unexpected or buggy dtype conversions label Jul 25, 2019
@mroeschke
Copy link
Member

This looks okay on master. Could use a test

In [4]: import pandas as pd
   ...:
   ...: df = pd.DataFrame({'a': [0.0], 'b': 0.0})
   ...:
   ...: df[['a', 'b']] = 0
   ...: print(df)
   ...: print()
   ...:
   ...: df['b'] = 0
   ...: print(df)
   a  b
0  0  0

   a  b
0  0  0

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions labels Jul 10, 2021
@jackgoldsmith4
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions good first issue Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
4 participants