Skip to content

Commit

Permalink
Merge branch 'MultiIndex.codes_docs' into MultiIndex.codes
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Nov 22, 2018
2 parents 46381c4 + b373e08 commit 6f741ee
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
7 changes: 6 additions & 1 deletion doc/source/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ analysis.

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

.. versionchanged:: 0.24.0

:attr:`MultiIndex.labels` has been renamed to :attr:`MultiIndex.codes`
and :attr:`MultiIndex.set_labels` to :attr:`MultiIndex.set_codes`.

Creating a MultiIndex (hierarchical index) object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -468,7 +473,7 @@ values across a level. For instance:
.. ipython:: python
midx = pd.MultiIndex(levels=[['zero', 'one'], ['x','y']],
labels=[[1,1,0,0],[1,0,1,0]])
codes=[[1,1,0,0],[1,0,1,0]])
df = pd.DataFrame(np.random.randn(4,2), index=midx)
df
df2 = df.mean(level=0)
Expand Down
4 changes: 2 additions & 2 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ MultiIndex Attributes

MultiIndex.names
MultiIndex.levels
MultiIndex.labels
MultiIndex.codes
MultiIndex.nlevels
MultiIndex.levshape

Expand All @@ -1722,7 +1722,7 @@ MultiIndex Components
:toctree: generated/

MultiIndex.set_levels
MultiIndex.set_labels
MultiIndex.set_codes
MultiIndex.to_hierarchical
MultiIndex.to_flat_index
MultiIndex.to_frame
Expand Down
2 changes: 1 addition & 1 deletion doc/source/dsintro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ From DataFrame using ``to_panel`` method
.. ipython:: python
:okwarning:
midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], labels=[[1,1,0,0],[1,0,1,0]])
midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], codes=[[1,1,0,0],[1,0,1,0]])
df = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx)
df.to_panel()
Expand Down
6 changes: 3 additions & 3 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1571,9 +1571,9 @@ Setting metadata

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

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

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

.. ipython:: python
Expand Down
10 changes: 5 additions & 5 deletions doc/source/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ MultiIndex
~~~~~~~~~~

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

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

Values
~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions doc/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3685,8 +3685,8 @@ storing/selecting from homogeneous index ``DataFrames``.
index = pd.MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
['one', 'two', 'three']],
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
names=['foo', 'bar'])
df_mi = pd.DataFrame(np.random.randn(10, 3), index=index,
columns=['A', 'B', 'C'])
Expand Down

0 comments on commit 6f741ee

Please sign in to comment.