Skip to content

Commit ddd29ae

Browse files
committed
DOC: sorting isn't (and wasn't) a problem for single key indexing
1 parent 85f45ff commit ddd29ae

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/multi/test_sorting.py

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

115115
def test_unsortedindex_doc_examples():
116116
# http://pandas.pydata.org/pandas-docs/stable/advanced.html#sorting-a-multiindex # noqa
117-
dfm = DataFrame({'jim': [0, 0, 1, 1],
118-
'joe': ['x', 'x', 'z', 'y'],
119-
'jolie': np.random.rand(4)})
117+
dfm = pd.DataFrame({'jim': [0, 0, 1, 1],
118+
'joe': ['x', 'x', 'z', 'y'],
119+
'jolie': list('abcd'),
120+
'values': np.random.rand(4)})
120121

121-
dfm = dfm.set_index(['jim', 'joe'])
122+
dfm = dfm.set_index(['jim', 'joe', 'jolie'])
122123
with tm.assert_produces_warning(PerformanceWarning):
123124
dfm.loc[(1, 'z')]
124125

@@ -134,7 +135,7 @@ def test_unsortedindex_doc_examples():
134135
dfm.loc[(0, 'y'):(1, 'z')]
135136

136137
assert dfm.index.is_lexsorted()
137-
assert dfm.index.lexsort_depth == 2
138+
assert dfm.index.lexsort_depth == 3
138139

139140

140141
def test_reconstruct_sort():

0 commit comments

Comments
 (0)