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

Deprecate getting the name from MultiIndex.levels #29032

Closed
TomAugspurger opened this issue Oct 16, 2019 · 7 comments · Fixed by #30574
Closed

Deprecate getting the name from MultiIndex.levels #29032

TomAugspurger opened this issue Oct 16, 2019 · 7 comments · Fixed by #30574
Labels
Blocker Blocking issue or pull request for an upcoming release Deprecate Functionality to remove in pandas MultiIndex
Milestone

Comments

@TomAugspurger
Copy link
Contributor

Follow up to #27242.

#27242 (comment)

@TomAugspurger TomAugspurger added MultiIndex Blocker Blocking issue or pull request for an upcoming release Deprecate Functionality to remove in pandas labels Oct 16, 2019
@TomAugspurger TomAugspurger added this to the 1.0 milestone Oct 16, 2019
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Oct 17, 2019
xref https://issues.apache.org/jira/browse/ARROW-6922 /
pandas-dev#27242 (comment)
/ pandas-dev#29032

No docs yet, since it isn't clear how this will eventually sort out. But
we at least want to preserve this behavior for 1.0
@TomAugspurger
Copy link
Contributor Author

FWIW, I'm probably OK with not deprecating .levels[i].name. I think it's a pretty common pattern, and it would be a large deprecation. The only downside is that you can get in a state where setting the name of a level is silently not reflected in the MI. But I can live with that.

In [6]: idx = pd.MultiIndex.from_product([['a'], [1, 2]], names=['a', 'b'])

In [7]: idx.levels[0].name = 'c'

In [8]: idx
Out[8]:
MultiIndex([('a', 1),
            ('a', 2)],
           names=['a', 'b'])

jreback pushed a commit that referenced this issue Oct 18, 2019
* API: Restore getting name from MultiIndex level

xref https://issues.apache.org/jira/browse/ARROW-6922 /
#27242 (comment)
/ #29032

No docs yet, since it isn't clear how this will eventually sort out. But
we at least want to preserve this behavior for 1.0

* fixups
@topper-123
Copy link
Contributor

So, where are we wrt to renaming to categories?

IMO the name categories (or a different name than levels) would actually be better, because levels also refers to the "columns" in a MultiIndex, e.g. in df.groupby(..., level='x').

@TomAugspurger
Copy link
Contributor Author

I think deprecating .levels in favor of something else (.categories) is a big change, much bigger than .codes was. My initial reaction is that the benefits to renaming aren't there yet, but happy to be convinced otherwise.

cc @jorisvandenbossche.

@jorisvandenbossche
Copy link
Member

I am personally also not fully convinced that renaming levels is worth it.
It's true that "levels" is used for somewhat different things (in keyword arguments it refers to the full level of a multi-index, while the attribute only gives the unique values for that level). But it's been like that, and we also have get_level_values for the other.

HawkinsBA pushed a commit to HawkinsBA/pandas that referenced this issue Oct 29, 2019
* API: Restore getting name from MultiIndex level

xref https://issues.apache.org/jira/browse/ARROW-6922 /
pandas-dev#27242 (comment)
/ pandas-dev#29032

No docs yet, since it isn't clear how this will eventually sort out. But
we at least want to preserve this behavior for 1.0

* fixups
@TomAugspurger
Copy link
Contributor Author

Any more thoughts here?

I'm probably OK with the behavior on master

  1. Getting the level name with .levels[i].name continues to work
  2. Setting .levels[i].name will silently do nothing.

If we go with that, we'll need to thoroughly document this behavior.

Regardless of what we do, the release notes in https://dev.pandas.io/docs/whatsnew/v1.0.0.html#multiindex-levels-do-not-hold-level-names-any-longer will need to be updated.

@jreback
Copy link
Contributor

jreback commented Oct 30, 2019

would be great if we could show a warning for 2 (but still do nothing)

@TomAugspurger
Copy link
Contributor Author

Pushed #29572 for the 1.0 docs.

I don't think warning for setting .names[i] is straightforward, and probably isn't a blocker for 1.0

proost pushed a commit to proost/pandas that referenced this issue Dec 19, 2019
* API: Restore getting name from MultiIndex level

xref https://issues.apache.org/jira/browse/ARROW-6922 /
pandas-dev#27242 (comment)
/ pandas-dev#29032

No docs yet, since it isn't clear how this will eventually sort out. But
we at least want to preserve this behavior for 1.0

* fixups
proost pushed a commit to proost/pandas that referenced this issue Dec 19, 2019
* API: Restore getting name from MultiIndex level

xref https://issues.apache.org/jira/browse/ARROW-6922 /
pandas-dev#27242 (comment)
/ pandas-dev#29032

No docs yet, since it isn't clear how this will eventually sort out. But
we at least want to preserve this behavior for 1.0

* fixups
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Dec 30, 2019
bongolegend pushed a commit to bongolegend/pandas that referenced this issue Jan 1, 2020
* API: Restore getting name from MultiIndex level

xref https://issues.apache.org/jira/browse/ARROW-6922 /
pandas-dev#27242 (comment)
/ pandas-dev#29032

No docs yet, since it isn't clear how this will eventually sort out. But
we at least want to preserve this behavior for 1.0

* fixups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker Blocking issue or pull request for an upcoming release Deprecate Functionality to remove in pandas MultiIndex
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants