Pandas version checks

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

  • [X] 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
df = pd.DataFrame(data={0: [0, 0, 3], 1: [1, 1, 0], "time": [0, 1, 2]})
df.set_index("time", inplace=True)
df.drop_duplicates(keep="last")

Issue Description

I get the following warning:

/home/tkoehne/apps/miniconda3/envs/testpd/lib/python3.10/site-packages/pandas/core/frame.py:6257: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)
  diff = Index(subset).difference(self.columns)

Expected Behavior

Internally, the changing of the index and subsequent checks for dropping shouldn't raise a FutureWarning, but rather adopt the future behavior by default.

Installed Versions

/home/tkoehne/apps/miniconda3/envs/testpd/lib/python3.10/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") INSTALLED VERSIONS ------------------ commit : ca60aab7340d9989d9428e11a51467658190bb6b python : 3.10.6.final.0 python-bits : 64 OS : Linux OS-release : 4.18.0-348.2.1.el8_5.x86_64 Version : #1 SMP Mon Nov 8 13:30:15 EST 2021 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 1.4.4 numpy : 1.23.3 pytz : 2022.1 dateutil : 2.8.2 setuptools : 65.5.0 pip : 22.2.2 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : 1.3.5 brotli : None fastparquet : None fsspec : None gcsfs : None markupsafe : None matplotlib : None numba : None numexpr : 2.8.3 odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None

Comment From: dannyi96

Have confirmed that this issue exists in latest released version 1.5 but is fixed in main ( for next 2.0 release ) via changes made in PR #49458 (in file pandas/core/indexes/base.py ).

[ CC: @mroeschke ] would this be a change which would need to be backported to 1.5 as well ? or its fine for fix to be in next 2.0 release ?

Comment From: mroeschke

Looks like https://github.com/pandas-dev/pandas/pull/49458 fixed this because FutureWarning was removed to enforce the deprecation; therefore, it can't be backported to 1.5.2 since it would be a breaking change.

Overall this will be fixed in 2.0. A backport PR would be accepted, but it needs to be based on the 1.5.x branch.

Comment From: phofl

I can see this on 1.4.4 but neither on 1.5.0 nor on 1.5.1,

Comment From: dannyi96

@phofl yes, you're right ( my bad, the issue is present on older versions 1.4.x & is handled in 1.5.x ) I believe we can close this issue.