Skip to content

BUG: assert_index_equal raises FutureWarning when comparing Index of Int64Dtype without checking order #47207

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
3 tasks done
SanderBeekhuis opened this issue Jun 3, 2022 · 1 comment · Fixed by #47325
Closed
3 tasks done
Labels
Bug Regression Functionality that used to work in a prior pandas version Warnings Warnings that appear or should be added to pandas
Milestone

Comments

@SanderBeekhuis
Copy link

Pandas version checks

  • 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 main branch of pandas.

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

@SanderBeekhuis SanderBeekhuis added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 3, 2022
@simonjayhawkins
Copy link
Member

Thanks @SanderBeekhuis for the report.

deprecation added in #42870

cc @jbrockmendel

@simonjayhawkins simonjayhawkins added Regression Functionality that used to work in a prior pandas version Warnings Warnings that appear or should be added to pandas and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 8, 2022
@simonjayhawkins simonjayhawkins added this to the 1.4.3 milestone Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression Functionality that used to work in a prior pandas version Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants