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

BUG: DataFrame.astype(dict) can cause column metadata to be lost #19920

Closed
jschendel opened this issue Feb 27, 2018 · 1 comment · Fixed by #19948
Closed

BUG: DataFrame.astype(dict) can cause column metadata to be lost #19920

jschendel opened this issue Feb 27, 2018 · 1 comment · Fixed by #19948
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@jschendel
Copy link
Member

Code Sample, a copy-pastable example if possible

Setup:

In [2]: df = pd.DataFrame(data=np.random.randint(5, size=(3, 4)),
   ...:                   columns=pd.UInt64Index(range(500, 504), name='foo'))
   ...:

In [3]: df
Out[3]:
foo  500  501  502  503
0      4    4    2    1
1      0    2    3    1
2      1    4    0    0

In [4]: df.columns
Out[4]: UInt64Index([500, 501, 502, 503], dtype='uint64', name='foo')

Using .astype(dict) loses column metadata:

In [5]: df = df.astype({500: 'float64', 501: 'uint64'})

In [6]: df.columns
Out[6]: Int64Index([500, 501, 502, 503], dtype='int64')

Problem description

Column metadata is lost: the name has been removed and it has been cast from UInt64Index to Int64Index.

Expected Output

I'd expect the columns post-astype to be the same as pre-astype.

@jschendel
Copy link
Member Author

xref #18099 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants