Skip to content

Commit 6f741ee

Browse files
committed
Merge branch 'MultiIndex.codes_docs' into MultiIndex.codes
2 parents 46381c4 + b373e08 commit 6f741ee

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

@@ -468,7 +473,7 @@ values across a level. For instance:
468473
.. ipython:: python
469474
470475
midx = pd.MultiIndex(levels=[['zero', 'one'], ['x','y']],
471-
labels=[[1,1,0,0],[1,0,1,0]])
476+
codes=[[1,1,0,0],[1,0,1,0]])
472477
df = pd.DataFrame(np.random.randn(4,2), index=midx)
473478
df
474479
df2 = df.mean(level=0)

doc/source/api.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ MultiIndex Attributes
17111711

17121712
MultiIndex.names
17131713
MultiIndex.levels
1714-
MultiIndex.labels
1714+
MultiIndex.codes
17151715
MultiIndex.nlevels
17161716
MultiIndex.levshape
17171717

@@ -1722,7 +1722,7 @@ MultiIndex Components
17221722
:toctree: generated/
17231723

17241724
MultiIndex.set_levels
1725-
MultiIndex.set_labels
1725+
MultiIndex.set_codes
17261726
MultiIndex.to_hierarchical
17271727
MultiIndex.to_flat_index
17281728
MultiIndex.to_frame

doc/source/dsintro.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ From DataFrame using ``to_panel`` method
923923
.. ipython:: python
924924
:okwarning:
925925
926-
midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], labels=[[1,1,0,0],[1,0,1,0]])
926+
midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], codes=[[1,1,0,0],[1,0,1,0]])
927927
df = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx)
928928
df.to_panel()
929929

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
@@ -73,22 +73,22 @@ MultiIndex
7373
~~~~~~~~~~
7474

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

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

9393
Values
9494
~~~~~~

doc/source/io.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -3685,8 +3685,8 @@ storing/selecting from homogeneous index ``DataFrames``.
36853685
36863686
index = pd.MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
36873687
['one', 'two', 'three']],
3688-
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
3689-
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
3688+
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
3689+
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
36903690
names=['foo', 'bar'])
36913691
df_mi = pd.DataFrame(np.random.randn(10, 3), index=index,
36923692
columns=['A', 'B', 'C'])

0 commit comments

Comments
 (0)