Skip to content

Commit 269cb3b

Browse files
committed
small doc updates
1 parent b234bdb commit 269cb3b

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

doc/source/advanced.rst

+11-11
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

+1-10
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ DataFrame.sort_index changes
720720
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
721721

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

725725
This is UNCHANGED between versions, but showing for illustration purposes:
726726

@@ -778,15 +778,6 @@ New Behavior:
778778
df.sort_index().index.is_lexsorted()
779779
df.sort_index().index.is_monotonic
780780

781-
Previous Behavior:
782-
783-
.. code-block:: ipython
784-
785-
New Behavior:
786-
787-
.. ipython:: python
788-
789-
790781
.. _whatsnew_0200.api_breaking.groupby_describe:
791782

792783
Groupby Describe Formatting

pandas/core/sorting.py

+16
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

+8-4
Original file line numberDiff line numberDiff line change
@@ -1175,10 +1175,14 @@ def from_product(cls, iterables, sortorder=None, names=None):
11751175

11761176
def _reconstruct(self, sort=False, remove_unused=False):
11771177
"""
1178-
reconstruct the MultiIndex
1178+
create a new MultiIndex from the current to provide either:
1179+
- monotonically sorted items IN the levels
1180+
- removing unused levels (meaning that they are not expressed
1181+
in the labels)
11791182
1180-
The MultiIndex will have the same outward appearance (e.g. values)
1181-
and will also .equals()
1183+
The resulting MultiIndex will have the same outward
1184+
appearance, meaning the same .values and ordering. It will also
1185+
be .equals() to the original.
11821186
11831187
Parameters
11841188
----------
@@ -1189,7 +1193,7 @@ def _reconstruct(self, sort=False, remove_unused=False):
11891193
11901194
Returns
11911195
-------
1192-
MultiIndex
1196+
new MultiIndex
11931197
11941198
"""
11951199

0 commit comments

Comments
 (0)