Skip to content
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

df.astype(dict) drops 'names' on a multiindex #27795

Closed
tunnij opened this issue Aug 7, 2019 · 2 comments
Closed

df.astype(dict) drops 'names' on a multiindex #27795

tunnij opened this issue Aug 7, 2019 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request

Comments

@tunnij
Copy link

tunnij commented Aug 7, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame(
    data=[1., 2., 3.],
    columns=pd.MultiIndex.from_tuples(
        [('A', 'X')],
        names=['Top', 'Bottom'],
    )
)
df2 = df.astype({('A', 'X'): 'int'})
print(df.columns.names)
print(df2.columns.names)

Problem description

df2 should have the same column.names as df. What actually happens is that the column.names become [None, None].

If instead the definition of df2 becomes:

df2 = df.astype('int')

Then the expected behavior is observed.

Expected Output

['Top', 'Bottom']

Output of pd.show_versions()

[paste the output of ``pd.show_versions()`` here below this line] INSTALLED VERSIONS ------------------ commit: None python: 2.7.15.final.0 python-bits: 64 OS: Linux OS-release: 3.10.0-327.36.3.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.22.0
pytest: 4.6.2
pip: 19.1.1
setuptools: 41.0.1
Cython: 0.28.5
numpy: 1.14.5
scipy: 1.0.1
pyarrow: None
xarray: 0.11.3
IPython: 5.8.0
sphinx: 1.8.5
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 2.2.3
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.8
lxml: 4.2.4
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.5
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@WillAyd
Copy link
Member

WillAyd commented Aug 7, 2019

This is a pretty old version of pandas - can you try on 0.25?

@WillAyd WillAyd added the Needs Info Clarification about behavior needed to assess issue label Aug 7, 2019
@jschendel
Copy link
Member

This is a dupe of #19920 and was fixed as part of 0.23.0.

@jschendel jschendel added Duplicate Report Duplicate issue or pull request and removed Needs Info Clarification about behavior needed to assess issue labels Aug 7, 2019
@jschendel jschendel added this to the No action milestone Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants