Skip to content

BUG: Accessing a cell in a pandas DataFrame with MultiIndex loses type information #41369

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
2 of 3 tasks
sam-s opened this issue May 7, 2021 · 2 comments · Fixed by #41374
Closed
2 of 3 tasks

BUG: Accessing a cell in a pandas DataFrame with MultiIndex loses type information #41369

sam-s opened this issue May 7, 2021 · 2 comments · Fixed by #41374
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions MultiIndex
Milestone

Comments

@sam-s
Copy link

sam-s commented May 7, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

df2 = pd.DataFrame([{"a":1.0,"b":2,"c":3,"d":4}]).set_index(["c","d"])
df2.loc[(3,4),"b"]

Problem description

the above returns 2.0 of type numpy.float64 instead of 2 of type numpy.int64 as it should since df2.dtypes["b"]
is dtype('int64').

See here for more information.

Expected Output

2

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.9.4.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Mon Apr 12 20:57:45 PDT 2021; root:xnu-6153.141.28.1~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : C
LOCALE : en_US.UTF-8

pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.1
setuptools : 54.2.0
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 7.23.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : 1.4.14
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@sam-s sam-s added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 7, 2021
@attack68
Copy link
Contributor

attack68 commented May 7, 2021

confirmed. and if you do:

df2.loc[[(3,4)],"b"].iloc[0] you get integer dtype: 2

@attack68 attack68 added MultiIndex Dtype Conversions Unexpected or buggy dtype conversions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 7, 2021
@phofl
Copy link
Member

phofl commented May 7, 2021

Yeah this is a tricky one.
We are retrieving a row as a series forcing the conversion here.

@jreback jreback added this to the 1.3 milestone May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions MultiIndex
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants