Skip to content

Commit 7463825

Browse files
committed
DOC: sorting isn't (and wasn't) a problem for single key indexing
1 parent 57d66a4 commit 7463825

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

doc/source/advanced.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,17 @@ they have a ``MultiIndex``:
535535
536536
df.T.sort_index(level=1, axis=1)
537537
538-
Indexing will work even if the data are not sorted, but will be rather
539-
inefficient (and show a ``PerformanceWarning``). It will also
538+
Indexing will work even if the data are not sorted, but partial indexing will
539+
be rather inefficient (and show a ``PerformanceWarning``). It will also
540540
return a copy of the data rather than a view:
541541

542542
.. ipython:: python
543543
544544
dfm = pd.DataFrame({'jim': [0, 0, 1, 1],
545545
'joe': ['x', 'x', 'z', 'y'],
546-
'jolie': np.random.rand(4)})
547-
dfm = dfm.set_index(['jim', 'joe'])
546+
'jolie': list('abcd'),
547+
'values' : np.random.rand(4)})
548+
dfm = dfm.set_index(['jim', 'joe', 'jolie'])
548549
dfm
549550
550551
.. code-block:: ipython
@@ -553,9 +554,9 @@ return a copy of the data rather than a view:
553554
PerformanceWarning: indexing past lexsort depth may impact performance.
554555
555556
Out[4]:
556-
jolie
557-
jim joe
558-
1 z 0.64094
557+
values
558+
jolie
559+
0.879189 c
559560
560561
.. _advanced.unsorted:
561562

pandas/tests/indexes/test_multi.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,11 +3205,12 @@ def test_unsortedindex(self):
32053205

32063206
def test_unsortedindex_doc_examples(self):
32073207
# http://pandas.pydata.org/pandas-docs/stable/advanced.html#sorting-a-multiindex # noqa
3208-
dfm = DataFrame({'jim': [0, 0, 1, 1],
3209-
'joe': ['x', 'x', 'z', 'y'],
3210-
'jolie': np.random.rand(4)})
3208+
dfm = pd.DataFrame({'jim': [0, 0, 1, 1],
3209+
'joe': ['x', 'x', 'z', 'y'],
3210+
'jolie': list('abcd'),
3211+
'values': np.random.rand(4)})
32113212

3212-
dfm = dfm.set_index(['jim', 'joe'])
3213+
dfm = dfm.set_index(['jim', 'joe', 'jolie'])
32133214
with tm.assert_produces_warning(PerformanceWarning):
32143215
dfm.loc[(1, 'z')]
32153216

@@ -3225,7 +3226,7 @@ def test_unsortedindex_doc_examples(self):
32253226
dfm.loc[(0, 'y'):(1, 'z')]
32263227

32273228
assert dfm.index.is_lexsorted()
3228-
assert dfm.index.lexsort_depth == 2
3229+
assert dfm.index.lexsort_depth == 3
32293230

32303231
def test_tuples_with_name_string(self):
32313232
# GH 15110 and GH 14848

0 commit comments

Comments
 (0)