Skip to content

BUG: MultiIndex constructed with nulls inconsistent with dtypes and get_level_values  #44792

Closed
@isVoid

Description

@isVoid

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

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

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

Reproducible Example

In [40]: pd.MultiIndex.from_arrays([[1, None, 2], [None, None, 3]]).dtypes
Out[40]: 
level_0    int64
level_1    int64
dtype: object
In [43]: pd.MultiIndex.from_arrays([[1, None, 2], [None, None, 3]]).get_level_values(0)
Out[43]: Float64Index([1.0, nan, 2.0], dtype='float64')
In [44]: pd.MultiIndex.from_arrays([[1, None, 2], [None, None, 3]]).get_level_values(1)
Out[44]: Float64Index([nan, nan, 3.0], dtype='float64')

Issue Description

dtypes reports that both levels are of integer types, but the returned level values are float types.

Expected Behavior

Eitherdtypes reports float types or dtypes reports nullable integer types and get_level_values returns that.

Installed Versions

INSTALLED VERSIONS

commit : 945c9ed
python : 3.8.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-40-generic
Version : #44~20.04.2-Ubuntu SMP Tue Oct 26 18:07:44 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8

pandas : 1.3.4
numpy : 1.20.3
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 59.4.0
Cython : 0.29.24
pytest : 6.2.5
hypothesis : 6.29.0
sphinx : 4.3.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.4
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 7.30.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fsspec : 2021.11.1
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.54.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateMultiIndex

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions