Skip to content

Commit cee5814

Browse files
committed
Change docs according to #23752
1 parent ae1b88f commit cee5814

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

doc/source/advanced.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ analysis.
4949

5050
See the :ref:`cookbook<cookbook.multi_index>` for some advanced strategies.
5151

52+
.. versionchanged:: 0.24.0
53+
54+
:attr:`MultiIndex.labels` has been renamed to :attr:`MultiIndex.codes`
55+
and :attr:`MultiIndex.set_labels` to :attr:`MultiIndex.set_codes`.
56+
5257
Creating a MultiIndex (hierarchical index) object
5358
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5459

@@ -469,7 +474,7 @@ values across a level. For instance:
469474
.. ipython:: python
470475
471476
midx = pd.MultiIndex(levels=[['zero', 'one'], ['x', 'y']],
472-
labels=[[1, 1, 0, 0], [1, 0, 1, 0]])
477+
codes=[[1, 1, 0, 0],[1, 0, 1, 0]])
473478
df = pd.DataFrame(np.random.randn(4, 2), index=midx)
474479
df
475480
df2 = df.mean(level=0)

doc/source/api.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ MultiIndex Attributes
17121712

17131713
MultiIndex.names
17141714
MultiIndex.levels
1715-
MultiIndex.labels
1715+
MultiIndex.codes
17161716
MultiIndex.nlevels
17171717
MultiIndex.levshape
17181718

@@ -1723,7 +1723,7 @@ MultiIndex Components
17231723
:toctree: generated/
17241724

17251725
MultiIndex.set_levels
1726-
MultiIndex.set_labels
1726+
MultiIndex.set_codes
17271727
MultiIndex.to_hierarchical
17281728
MultiIndex.to_flat_index
17291729
MultiIndex.to_frame

doc/source/dsintro.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ From DataFrame using ``to_panel`` method
961961
.. ipython:: python
962962
:okwarning:
963963
964-
midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], labels=[[1,1,0,0],[1,0,1,0]])
964+
midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], codes=[[1,1,0,0],[1,0,1,0]])
965965
df = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx)
966966
df.to_panel()
967967

doc/source/indexing.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1571,9 +1571,9 @@ Setting metadata
15711571

15721572
Indexes are "mostly immutable", but it is possible to set and change their
15731573
metadata, like the index ``name`` (or, for ``MultiIndex``, ``levels`` and
1574-
``labels``).
1574+
``codes``).
15751575

1576-
You can use the ``rename``, ``set_names``, ``set_levels``, and ``set_labels``
1576+
You can use the ``rename``, ``set_names``, ``set_levels``, and ``set_codes``
15771577
to set these attributes directly. They default to returning a copy; however,
15781578
you can specify ``inplace=True`` to have the data change in place.
15791579

@@ -1588,7 +1588,7 @@ See :ref:`Advanced Indexing <advanced>` for usage of MultiIndexes.
15881588
ind.name = "bob"
15891589
ind
15901590
1591-
``set_names``, ``set_levels``, and ``set_labels`` also take an optional
1591+
``set_names``, ``set_levels``, and ``set_codes`` also take an optional
15921592
`level`` argument
15931593

15941594
.. ipython:: python

doc/source/internals.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ MultiIndex
7474
~~~~~~~~~~
7575

7676
Internally, the ``MultiIndex`` consists of a few things: the **levels**, the
77-
integer **labels**, and the level **names**:
77+
integer **codes** (until version 0.24 named *labels*), and the level **names**:
7878

7979
.. ipython:: python
8080
8181
index = pd.MultiIndex.from_product([range(3), ['one', 'two']],
8282
names=['first', 'second'])
8383
index
8484
index.levels
85-
index.labels
85+
index.codes
8686
index.names
8787
88-
You can probably guess that the labels determine which unique element is
88+
You can probably guess that the codes determine which unique element is
8989
identified with that location at each layer of the index. It's important to
90-
note that sortedness is determined **solely** from the integer labels and does
90+
note that sortedness is determined **solely** from the integer codes and does
9191
not check (or care) whether the levels themselves are sorted. Fortunately, the
9292
constructors ``from_tuples`` and ``from_arrays`` ensure that this is true, but
93-
if you compute the levels and labels yourself, please be careful.
93+
if you compute the levels and codes yourself, please be careful.
9494

9595
Values
9696
~~~~~~

doc/source/io.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -3728,8 +3728,8 @@ storing/selecting from homogeneous index ``DataFrames``.
37283728
37293729
index = pd.MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
37303730
['one', 'two', 'three']],
3731-
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
3732-
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
3731+
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
3732+
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
37333733
names=['foo', 'bar'])
37343734
df_mi = pd.DataFrame(np.random.randn(10, 3), index=index,
37353735
columns=['A', 'B', 'C'])

0 commit comments

Comments
 (0)