Skip to content

Commit 804af26

Browse files
committed
DOC: sorting isn't (and wasn't) a problem for single key indexing
1 parent d4aa4c4 commit 804af26

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

doc/source/advanced.rst

+8-7
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,17 @@ they have a ``MultiIndex``:
503503
504504
df.T.sort_index(level=1, axis=1)
505505
506-
Indexing will work even if the data are not sorted, but will be rather
507-
inefficient (and show a ``PerformanceWarning``). It will also
506+
Indexing will work even if the data are not sorted, but partial indexing will
507+
be rather inefficient (and show a ``PerformanceWarning``). It will also
508508
return a copy of the data rather than a view:
509509

510510
.. ipython:: python
511511
512512
dfm = pd.DataFrame({'jim': [0, 0, 1, 1],
513513
'joe': ['x', 'x', 'z', 'y'],
514-
'jolie': np.random.rand(4)})
515-
dfm = dfm.set_index(['jim', 'joe'])
514+
'jolie': list('abcd'),
515+
'values' : np.random.rand(4)})
516+
dfm = dfm.set_index(['jim', 'joe', 'jolie'])
516517
dfm
517518
518519
.. code-block:: ipython
@@ -521,9 +522,9 @@ return a copy of the data rather than a view:
521522
PerformanceWarning: indexing past lexsort depth may impact performance.
522523
523524
Out[4]:
524-
jolie
525-
jim joe
526-
1 z 0.64094
525+
values
526+
jolie
527+
0.879189 c
527528
528529
.. _advanced.unsorted:
529530

pandas/tests/indexes/test_multi.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -3109,11 +3109,12 @@ def test_unsortedindex(self):
31093109

31103110
def test_unsortedindex_doc_examples(self):
31113111
# http://pandas.pydata.org/pandas-docs/stable/advanced.html#sorting-a-multiindex # noqa
3112-
dfm = DataFrame({'jim': [0, 0, 1, 1],
3113-
'joe': ['x', 'x', 'z', 'y'],
3114-
'jolie': np.random.rand(4)})
3112+
dfm = pd.DataFrame({'jim': [0, 0, 1, 1],
3113+
'joe': ['x', 'x', 'z', 'y'],
3114+
'jolie': list('abcd'),
3115+
'values': np.random.rand(4)})
31153116

3116-
dfm = dfm.set_index(['jim', 'joe'])
3117+
dfm = dfm.set_index(['jim', 'joe', 'jolie'])
31173118
with tm.assert_produces_warning(PerformanceWarning):
31183119
dfm.loc[(1, 'z')]
31193120

@@ -3129,7 +3130,7 @@ def test_unsortedindex_doc_examples(self):
31293130
dfm.loc[(0, 'y'):(1, 'z')]
31303131

31313132
assert dfm.index.is_lexsorted()
3132-
assert dfm.index.lexsort_depth == 2
3133+
assert dfm.index.lexsort_depth == 3
31333134

31343135
def test_tuples_with_name_string(self):
31353136
# GH 15110 and GH 14848

0 commit comments

Comments
 (0)