Skip to content

BUG: DataFrame/Series.rename silently downcasts nullable index/column dtypes to NumPy dtypes #65315

@gautamvarmadatla

Description

@gautamvarmadatla

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

df = pd.DataFrame(
      {"val": [1, 2, 3]},
      index=pd.Index(pd.array([1, 2, 3], dtype="Int64"), name="id"),
  )
print(df.index.dtype)
print(df.rename({1: 9}).index.dtype)

Issue Description

DataFrame.rename() and Series.rename() do not preserve nullable extension dtypes on index/column labels. In the reproduced cases with nullable integer and floating dtypes, renaming labels silently downcasts the result to the corresponding NumPy dtype.

The root cause appears to be Index._transform_index(), which reconstructs the transformed index from a plain Python list instead of preserving/casting through the original ExtensionArray dtype.

Expected Behavior

rename() should preserve the original index dtype after relabeling.

Installed Versions

Details

INSTALLED VERSIONS

commit : 2a7587f
python : 3.12.12
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.26200
machine : AMD64
processor : Intel64 Family 6 Model 183 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 3.1.0.dev0+526.g2a7587fed0.dirty
numpy : 2.4.2
dateutil : 2.9.0.post0
pip : 26.0.1
Cython : 3.2.4
sphinx : None
IPython : 9.10.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : 1.6.0
fastparquet : None
fsspec : None
html5lib : None
hypothesis : 6.151.6
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : 3.10.8
numba : None
numexpr : 2.14.1
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyiceberg : None
pyreadstat : None
pytest : 9.0.2
python-calamine : None
pytz : 2025.2
pyxlsb : None
s3fs : None
scipy : 1.17.0
sqlalchemy : 2.0.46
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExtensionArrayExtending pandas with custom dtypes or arrays.IndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions