BUG: assert_index_equal raises FutureWarning when comparing Index of Int64Dtype without checking order · Issue #47207 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd from pandas._testing import assert_index_equal

assert_index_equal( pd.Index([1, 3], dtype=pd.Int64Dtype()), pd.Index([3, 1], dtype=pd.Int64Dtype()), check_order=False )

...\lib\site-packages\pandas_testing\asserters.py:377: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)

left = Index(safe_sort(left))

...\lib\site-packages\pandas_testing\asserters.py:378: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)

right = Index(safe_sort(right))

Issue Description

When comparing two indices of Int64Dtype(), without checking their order a FutureWarning is raised.

This seems to be caused by the fact that safe_sort changes the "Dtype" of the index to "object". I'm not sure how to best resolve this issue, but would be willing to contribute to it.

Expected Behavior

No FutureWarning is raised when comparing two indices.

Installed Versions

INSTALLED VERSIONS

commit : 4791cd7
python : 3.10.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 7, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.5.0.dev0+859.g4791cd75c0
numpy : 1.21.6
pytz : 2022.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 22.1.2
Cython : 0.29.30
pytest : 7.1.2
hypothesis : 6.46.7
sphinx : 4.5.0
blosc : 1.10.6
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.8.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.3.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.4
brotli : None
fastparquet : 0.8.1
fsspec : 2021.11.0
gcsfs : 2021.11.0
matplotlib : 3.5.2
numba : 0.55.1
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 8.0.0
pyreadstat : 1.1.6
pyxlsb : None
s3fs : 2021.11.0
scipy : 1.8.1
snappy :
sqlalchemy : 1.4.36
tables : 3.7.0
tabulate : 0.8.9
xarray : 2022.3.0
xlrd : 2.0.1
xlwt : 1.3.0
zstandard : None