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

Wrong dtype when mixed dtype DataFrame is accessed with complete indexer #14337

Closed
toobaz opened this issue Oct 3, 2016 · 2 comments
Closed
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

@toobaz
Copy link
Member

toobaz commented Oct 3, 2016

A small, complete example of the issue

In [2]: df = pd.DataFrame({'float' : range(4),
   ...:                    'int'   : range(4)},
   ...:                   index=pd.MultiIndex.from_product([[1,2]]*2))

In [3]: df['float'] = df['float'].astype(float)

In [4]: df.loc[(1,), 'int']
Out[4]: 
1    0
2    1
Name: int, dtype: int64

Right!

In [5]: df.loc[(1,), 'int'].loc[1]
Out[5]: 0

Right!

In [6]: df.loc[(1,1), 'int']
Out[6]: 0.0

Wrong!

Expected Output

Still an integer.

Output of pd.show_versions()

In [7]: pd.show_versions() ## INSTALLED VERSIONS

commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.5.0-2-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: it_IT.utf8
LOCALE: it_IT.UTF-8

pandas: 0.19.0+1.g96b364a
nose: 1.3.7
pip: 1.5.6
setuptools: 18.4
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.16.0
statsmodels: 0.8.0.dev0+f80669e
xarray: None
IPython: 5.1.0.dev
sphinx: 1.4.5
patsy: 0.3.0-dev
dateutil: 2.2
pytz: 2012c
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.5
matplotlib: 1.5.1
openpyxl: None
xlrd: 0.9.4
xlwt: 1.1.2
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.0
html5lib: 0.999
httplib2: 0.9.1
apiclient: 1.5.0
sqlalchemy: 1.0.11
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: 0.2.1

@toobaz
Copy link
Member Author

toobaz commented Oct 3, 2016

Oh, my example above is actually unnecessarily complicated - the index can be a normal Int64Index, as in

In [8]: df = pd.DataFrame({'float' : range(4),
   ...:                    'int'   : range(4)})

In [9]: df['float'] = df['float'].astype(float)

In [10]: df.loc[2, 'int']
Out[10]: 2.0

@jreback
Copy link
Contributor

jreback commented Oct 3, 2016

duplicate of #11617

@jreback jreback closed this as completed Oct 3, 2016
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request labels Oct 3, 2016
@jreback jreback added this to the No action milestone Oct 3, 2016
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

2 participants