Skip to content

Commit 9955590

Browse files
committed
small doc updates
1 parent dc28dff commit 9955590

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

doc/source/advanced.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ can find yourself working with hierarchically-indexed data without creating a
136136
may wish to generate your own ``MultiIndex`` when preparing the data set.
137137

138138
Note that how the index is displayed by be controlled using the
139-
``multi_sparse`` option in ``pandas.set_printoptions``:
139+
``multi_sparse`` option in ``pandas.set_options()``:
140140

141141
.. ipython:: python
142142
@@ -288,7 +288,7 @@ As usual, **both sides** of the slicers are included as this is label indexing.
288288

289289
.. code-block:: python
290290
291-
df.loc[(slice('A1','A3'),.....),:]
291+
df.loc[(slice('A1','A3'),.....), :]
292292
293293
rather than this:
294294

@@ -317,51 +317,51 @@ Basic multi-index slicing using slices, lists, and labels.
317317

318318
.. ipython:: python
319319
320-
dfmi.loc[(slice('A1','A3'),slice(None), ['C1','C3']),:]
320+
dfmi.loc[(slice('A1','A3'), slice(None), ['C1', 'C3']), :]
321321
322322
You can use a ``pd.IndexSlice`` to have a more natural syntax using ``:`` rather than using ``slice(None)``
323323

324324
.. ipython:: python
325325
326326
idx = pd.IndexSlice
327-
dfmi.loc[idx[:,:,['C1','C3']],idx[:,'foo']]
327+
dfmi.loc[idx[:, :, ['C1', 'C3']], idx[:, 'foo']]
328328
329329
It is possible to perform quite complicated selections using this method on multiple
330330
axes at the same time.
331331

332332
.. ipython:: python
333333
334-
dfmi.loc['A1',(slice(None),'foo')]
335-
dfmi.loc[idx[:,:,['C1','C3']],idx[:,'foo']]
334+
dfmi.loc['A1', (slice(None), 'foo')]
335+
dfmi.loc[idx[:, :, ['C1', 'C3']], idx[:, 'foo']]
336336
337337
Using a boolean indexer you can provide selection related to the *values*.
338338

339339
.. ipython:: python
340340
341-
mask = dfmi[('a','foo')]>200
342-
dfmi.loc[idx[mask,:,['C1','C3']],idx[:,'foo']]
341+
mask = dfmi[('a', 'foo')] > 200
342+
dfmi.loc[idx[mask, :, ['C1', 'C3']], idx[:, 'foo']]
343343
344344
You can also specify the ``axis`` argument to ``.loc`` to interpret the passed
345345
slicers on a single axis.
346346

347347
.. ipython:: python
348348
349-
dfmi.loc(axis=0)[:,:,['C1','C3']]
349+
dfmi.loc(axis=0)[:, :, ['C1', 'C3']]
350350
351351
Furthermore you can *set* the values using these methods
352352

353353
.. ipython:: python
354354
355355
df2 = dfmi.copy()
356-
df2.loc(axis=0)[:,:,['C1','C3']] = -10
356+
df2.loc(axis=0)[:, :, ['C1', 'C3']] = -10
357357
df2
358358
359359
You can use a right-hand-side of an alignable object as well.
360360

361361
.. ipython:: python
362362
363363
df2 = dfmi.copy()
364-
df2.loc[idx[:,:,['C1','C3']],:] = df2*1000
364+
df2.loc[idx[:, :, ['C1', 'C3']], :] = df2 * 1000
365365
df2
366366
367367
.. _advanced.xs:

doc/source/whatsnew/v0.20.0.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ DataFrame.sort_index changes
662662
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
663663

664664
In certain cases, calling ``.sort_index()`` on a MultiIndexed DataFrame would return the *same* DataFrame without seeming to sort.
665-
This would happen with a ``lexsorted``, but non-montonic levels. (:issue:`15622`, :issue:`15687`, :issue:`14015`, :issue:`13431`)
665+
This would happen with a ``lexsorted``, but non-monotonic levels. (:issue:`15622`, :issue:`15687`, :issue:`14015`, :issue:`13431`)
666666

667667
This is UNCHANGED between versions, but showing for illustration purposes:
668668

@@ -720,15 +720,6 @@ New Behavior:
720720
df.sort_index().index.is_lexsorted()
721721
df.sort_index().index.is_monotonic
722722

723-
Previous Behavior:
724-
725-
.. code-block:: ipython
726-
727-
New Behavior:
728-
729-
.. ipython:: python
730-
731-
732723
.. _whatsnew_0200.api_breaking.groupby_describe:
733724

734725
Groupby Describe Formatting

pandas/core/sorting.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ def maybe_lift(lab, size): # pormote nan values
9494

9595

9696
def get_compressed_ids(labels, sizes):
97+
"""
98+
99+
Group_index is offsets into cartesian product of all possible labels. This
100+
space can be huge, so this function compresses it, by computing offsets
101+
(comp_ids) into the list of unique labels (obs_group_ids).
102+
103+
Parameters
104+
----------
105+
labels : list of label arrays
106+
sizes : list of size of the levels
107+
108+
Returns
109+
-------
110+
tuple of (comp_ids, obs_group_ids)
111+
112+
"""
97113
ids = get_group_index(labels, sizes, sort=True, xnull=False)
98114
return compress_group_index(ids, sort=True)
99115

pandas/indexes/multi.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,10 +1177,14 @@ def from_product(cls, iterables, sortorder=None, names=None):
11771177

11781178
def _reconstruct(self, sort=False, remove_unused=False):
11791179
"""
1180-
reconstruct the MultiIndex
1180+
create a new MultiIndex from the current to provide either:
1181+
- monotonically sorted items IN the levels
1182+
- removing unused levels (meaning that they are not expressed
1183+
in the labels)
11811184
1182-
The MultiIndex will have the same outward appearance (e.g. values)
1183-
and will also .equals()
1185+
The resulting MultiIndex will have the same outward
1186+
appearance, meaning the same .values and ordering. It will also
1187+
be .equals() to the original.
11841188
11851189
Parameters
11861190
----------
@@ -1191,7 +1195,7 @@ def _reconstruct(self, sort=False, remove_unused=False):
11911195
11921196
Returns
11931197
-------
1194-
MultiIndex
1198+
new MultiIndex
11951199
11961200
"""
11971201

0 commit comments

Comments
 (0)