API: rename MultiIndex.labels to MultiIndex.codes
State: closed

- [x] closes #13443
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

This PR renames ``MultiIndex.labels`` to ``MultiIndex.codes``.

Also note that I've not changed the repr method or the repr output in various doc strings examples in anticipation of #22511 (this would be unneeded extra work). This should all be ok when #22511 is merged.

I would appreciate comments on the changes quickly, as this is a very large PR that touches on many parts of pandas, so it quickly gets out of sync.

@jorisvandenbossche?


Labels:
name: API Design
name: MultiIndex
name: Deprecate
description: Functionality to remove in pandas

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23752?src=pr&el=h1) Report
> Merging [#23752](https://codecov.io/gh/pandas-dev/pandas/pull/23752?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9f2c7164ec581a484ee167c04478bf9e4f81426b?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `95.76%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/23752/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23752?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #23752      +/-   ##
==========================================
+ Coverage    92.2%    92.2%   +<.01%     
==========================================
  Files         162      162              
  Lines       51714    51724      +10     
==========================================
+ Hits        47682    47692      +10     
  Misses       4032     4032
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.6% <93.81%> (ø)` | :arrow_up: |
| #single | `43.02% <27.03%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23752?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/window.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvd2luZG93LnB5) | `96.39% <ø> (ø)` | :arrow_up: |
| [pandas/core/groupby/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9nZW5lcmljLnB5) | `87.07% <0%> (ø)` | :arrow_up: |
| [pandas/core/util/hashing.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdXRpbC9oYXNoaW5nLnB5) | `98.4% <100%> (ø)` | :arrow_up: |
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `99.56% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.32% <100%> (ø)` | :arrow_up: |
| [pandas/core/groupby/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9vcHMucHk=) | `96.72% <100%> (ø)` | :arrow_up: |
| [pandas/core/reshape/merge.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZXJnZS5weQ==) | `94.28% <100%> (ø)` | :arrow_up: |
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `94.84% <100%> (ø)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `87.41% <100%> (ø)` | :arrow_up: |
| [pandas/core/panel.py](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcGFuZWwucHk=) | `97.91% <100%> (ø)` | :arrow_up: |
| ... and [6 more](https://codecov.io/gh/pandas-dev/pandas/pull/23752/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23752?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23752?src=pr&el=footer). Last update [9f2c716...a8d00ad](https://codecov.io/gh/pandas-dev/pandas/pull/23752?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

I've updated now. The Travis failure is  unrelated (it's a unrelated test that consumes too much memory):

```
Worker 'gw1' crashed while running 'pandas/tests/series/test_rank.py::test_pct_max_many_rows'
```

I've also caught/done a few more renames, see latest commit. 

I'll start up updating the docs tonight or tomorrow. I'll do the doc changes in a seperate PR, as the current PR already is very large.
Hey, is this ok?

This touches a lot of things, so very quickly gets into conflicts...
I think the Azure logs are more difficult to read than the Travis ones.

Can anyone help decipering if there's anything wrong or this is actually ok?
@topper-123 : Yikes!  This is definitely not readable at all.

We need to get this fixed in a separate PR (see #22854).
This azure checks ar stalled, but looks ok to me: It [reports the bug below](https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=4664)

```
2018-12-04T07:41:21.1391588Z ##[error]./asv_bench/benchmarks/frame_methods.py(2,1): error F401: 'warnings' imported but unused
```

My Pr doesn't touch frame_methods.py, os I think this is a case of the new azure tests being too eager.

I'm make a seperate PR remove the ``import warnings`` line from frame_methods.py
> My Pr doesn't touch frame_methods.py, os I think this is a case of the new azure tests being too eager.

not its not too eager, its an issue with the asv's that was not being properly caught before. wait a little and will let you know when to rebase.


Rebased & green.
thanks @topper-123 nice change!
Thanks a lot for this @topper-123 !
There are still a bunch of warnings in the docs that should be fixed:

```
>>>-------------------------------------------------------------------------
Warning in /home/travis/build/pandas-dev/pandas/doc/source/io.rst at block ending on line 4631
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
/home/travis/miniconda3/envs/pandas-dev/lib/python3.6/site-packages/pyarrow/pandas_compat.py:742: FutureWarning: .labels was deprecated in version 0.24.0. Use .codes instead.
  labels, = index.labels
<<<-------------------------------------------------------------------------
>>>-------------------------------------------------------------------------
Warning in /home/travis/build/pandas-dev/pandas/doc/source/io.rst at block ending on line 4704
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
/home/travis/miniconda3/envs/pandas-dev/lib/python3.6/site-packages/pyarrow/pandas_compat.py:698: FutureWarning: .labels was deprecated in version 0.24.0. Use .codes instead.
  labels = getattr(columns, 'labels', None) or [
<<<-------------------------------------------------------------------------
>>>-------------------------------------------------------------------------
Warning in /home/travis/build/pandas-dev/pandas/doc/source/io.rst at block ending on line 4704
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
/home/travis/miniconda3/envs/pandas-dev/lib/python3.6/site-packages/pyarrow/pandas_compat.py:725: FutureWarning: the 'labels' keyword is deprecated, use 'codes' instead
  return pd.MultiIndex(levels=new_levels, labels=labels, names=columns.names)
<<<-------------------------------------------------------------------------
>>>-------------------------------------------------------------------------
Warning in /home/travis/build/pandas-dev/pandas/doc/source/io.rst at block ending on line 4704
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
/home/travis/miniconda3/envs/pandas-dev/lib/python3.6/site-packages/pyarrow/pandas_compat.py:742: FutureWarning: .labels was deprecated in version 0.24.0. Use .codes instead.
  labels, = index.labels
<<<-------------------------------------------------------------------------
>>>-------------------------------------------------------------------------
Warning in /home/travis/build/pandas-dev/pandas/doc/source/io.rst at block ending on line 4768
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
/home/travis/miniconda3/envs/pandas-dev/lib/python3.6/site-packages/pyarrow/pandas_compat.py:698: FutureWarning: .labels was deprecated in version 0.24.0. Use .codes instead.
  labels = getattr(columns, 'labels', None) or [
<<<-------------------------------------------------------------------------
>>>-------------------------------------------------------------------------
Warning in /home/travis/build/pandas-dev/pandas/doc/source/io.rst at block ending on line 4768
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
/home/travis/miniconda3/envs/pandas-dev/lib/python3.6/site-packages/pyarrow/pandas_compat.py:725: FutureWarning: the 'labels' keyword is deprecated, use 'codes' instead
  return pd.MultiIndex(levels=new_levels, labels=labels, names=columns.names)
<<<-------------------------------------------------------------------------
>>>-------------------------------------------------------------------------
Warning in /home/travis/build/pandas-dev/pandas/doc/source/io.rst at block ending on line 4768
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
/home/travis/miniconda3/envs/pandas-dev/lib/python3.6/site-packages/pyarrow/pandas_compat.py:742: FutureWarning: .labels was deprecated in version 0.24.0. Use .codes instead.
  labels, = index.labels
<<<-------------------------------------------------------------------------
```
Ah, they all seem to come from parquet / feather. Will report upstream.
There are some other in the whatsnew files as well