BUG: DataFrame.convert_dtypes() drops the columns' name · Issue #41435 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example

import pandas as pd

df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]}) df.columns.name = 'cols' print(df)

drops the columns' name 'cols'

print(df.convert_dtypes())

Problem description

DataFrame.convert_dtypes() drops the columns' name.
This is unexpected.

Expected Output

convert_dtypes() should keep the columns' name.
It does so for the index name.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.8.8.final.0
python-bits : 64
OS : Linux
OS-release : 5.8.0-50-generic
Version : #56~20.04.1-Ubuntu SMP Mon Apr 12 21:46:35 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.4
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0.post20210125
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 : None
fsspec : 0.9.0
fastparquet : None
gcsfs : None
matplotlib : 3.3.4
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.0
pyxlsb : None
s3fs : 0.6.0
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None