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

pandas.index.copy remove index name information when specifying new dtype #32013

Closed
asepwhite opened this issue Feb 15, 2020 · 1 comment · Fixed by #32036
Closed

pandas.index.copy remove index name information when specifying new dtype #32013

asepwhite opened this issue Feb 15, 2020 · 1 comment · Fixed by #32036
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@asepwhite
Copy link
Contributor

Code Sample, a copy-pastable example if possible

>>> import pandas as pd
>>> named_idx = pd.Index([17.3, 69.221, 33.1, 15.5, 19.3, 74.8, 10, 5.5]).set_names('old_name')
>>> named_idx
Float64Index([17.3, 69.221, 33.1, 15.5, 19.3, 74.8, 10.0, 5.5], dtype='float64', name='old_name')
>>> named_idx.copy(name='new_name', dtype='int64')
Int64Index([17, 69, 33, 15, 19, 74, 10, 5], dtype='int64')
>>> named_idx.copy(dtype='int64')
Int64Index([17, 69, 33, 15, 19, 74, 10, 5], dtype='int64')

Problem description

When set new dtype parameter in function pandas.index.copy somehow it remove name information on new object

Expected Output

import pandas as pd
named_idx = pd.Index([17.3, 69.221, 33.1, 15.5, 19.3, 74.8, 10, 5.5]).set_names('old_name')
named_idx
Float64Index([17.3, 69.221, 33.1, 15.5, 19.3, 74.8, 10.0, 5.5], dtype='float64', name='old_name')
named_idx.copy(name='new_name', dtype='int64')
Int64Index([17, 69, 33, 15, 19, 74, 10, 5], dtype='int64', name='new_name')
named_idx.copy(dtype='int64')
Int64Index([17, 69, 33, 15, 19, 74, 10, 5], dtype='int64', name='old_name')

Output of pd.show_versions()

>>> pd.show_versions()

INSTALLED VERSIONS

{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}

{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}
{k:<17}: {stat}

@asepwhite asepwhite changed the title pandas.index.copy remove index name when specifying new dtype pandas.index.copy remove index name information when specifying new dtype Feb 15, 2020
@dsaxton
Copy link
Member

dsaxton commented Feb 16, 2020

Thanks, this looks like a bug

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Feb 16, 2020
@jreback jreback added this to the 1.1 milestone Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants