Skip to content
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

Selecting an element or row of mixed int/float DataFrame returns all floats #14361

Closed
nileracecrew opened this issue Oct 5, 2016 · 3 comments
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@nileracecrew
Copy link
Contributor

A small, complete example of the issue

In [37]: df = pd.DataFrame(dict(a=[0,1,2,3],b=[0.0,1.0,2.0,3.0]))

In [38]: df
Out[38]:
   a    b
0  0  0.0
1  1  1.0
2  2  2.0
3  3  3.0

In [39]: df.dtypes
Out[39]:
a      int64
b    float64
dtype: object

In [40]: df.iloc[0]
Out[40]:
a    0.0
b    0.0
Name: 0, dtype: float64

In [41]: df.loc[1,'a']
Out[41]: 1.0

Expected Output

Any values from column 'a' should still be ints.

Output of pd.show_versions()

## INSTALLED VERSIONS

commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 15.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None

@nileracecrew nileracecrew changed the title Selecting an element or row of mixed int/float DataFrame returns a row with all floats Selecting an element or row of mixed int/float DataFrame returns all floats Oct 5, 2016
@TomAugspurger TomAugspurger added Indexing Related to indexing on series/frames, not to indexes themselves Dtype Conversions Unexpected or buggy dtype conversions labels Oct 6, 2016
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 6, 2016

Your Out[40] is the correct behavior, since a Series (which is what that slice returns) can only have a single dtype, the int will be cast to a float.

I thought we had an open issue for your Out[41], but wasn't able to find it; thanks for reporting it.

@sinhrks
Copy link
Member

sinhrks commented Oct 6, 2016

Out[41] is a dupe with #11617. Thx for the report.

@sinhrks sinhrks closed this as completed Oct 6, 2016
@sinhrks sinhrks added this to the No action milestone Oct 6, 2016
@sinhrks sinhrks added the Duplicate Report Duplicate issue or pull request label Oct 6, 2016
@nileracecrew
Copy link
Contributor Author

Your Out[40] is the correct behavior, since a Series (which is what that slice returns) can only have a single dtype, the int will be cast to a float.

It could be returned as object, which what happens when some columns are non-numeric. But I guess this is done for understandable performance reasons.

Thanks.

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 Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

3 participants