Skip to content

Discussion: Should reindex keep the index name if new index has none #9885

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

Closed
hsperr opened this issue Apr 13, 2015 · 4 comments
Closed

Discussion: Should reindex keep the index name if new index has none #9885

hsperr opened this issue Apr 13, 2015 · 4 comments
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Needs Discussion Requires discussion from core team before further action

Comments

@hsperr
Copy link
Contributor

hsperr commented Apr 13, 2015

As mentioned in #6552 there is an open question about whether reindex should keep the index name if the new index has no name.

Current Behavior:

  • reindex keeps index name if the argument is a list or an ndarray
  • replaces the index name if the argument is an index, even if the new index does not have a new name.

Related Issues:
#9854

@jreback jreback added this to the Next Major Release milestone Apr 13, 2015
@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Apr 13, 2015
@TomAugspurger
Copy link
Contributor

There isn't an obvious answer to me for this one.

Also keep in mind that we have reindex_like. That one isn't clear either, but they should probably have the same behavior? Maybe?

@shoyer
Copy link
Member

shoyer commented Apr 17, 2015

I think reindex and reindex_like should definitely have the same behavior.

We do technically associate the name of an index with the index itself, but from a practical perspective the name of an index is also strongly associated with the dataframe that contains it (somewhat similarly to the case for Series.name and DataFrame.columns). In my opinion, it is a little surprising (even if it happens rarely) for reindexing to rename existing indexes -- it makes it harder to understand how the data was transformed. So my vote is for reindexing to never change index names.

@attack68
Copy link
Contributor

I'm developing an application which uses this feature. I came across page researching a bug in my application. I have used re_index to readjust on the fly to a function local Index variable which I did not bother to assign a name to. Reindex therefore dropped my index name and it broke down the line.

I would suggest that the index name is preserved if:

the reindex argument is a list, ndarray or Index which does not have a name,

and the index name is renamed if:

the reindex argument is an Index which has a specific name.

Perhaps an optional 'name_transform=None' argument could be added with the default behaviour as above and further 'drop' or 'keep' options to explicitly define the behaviour.

@mroeschke mroeschke added Needs Discussion Requires discussion from core team before further action and removed API Design labels Apr 18, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@mroeschke
Copy link
Member

Thanks for the issue but it appears there hasn't been much movement towards an action item here so closing. Happy to have a new issue with the discussion if there's interest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

6 participants