BUG: Accessing a cell in a pandas DataFrame with MultiIndex loses type information · Issue #41369 · pandas-dev/pandas (original) (raw)


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