Skip to content

Commit 31d4d8b

Browse files
authored
DOC: fix an example in whatsnew/v0.15.2.rst (#54986)
fix example in whatsnew/v0.15.2.rst
1 parent 4d3b536 commit 31d4d8b

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

doc/source/whatsnew/v0.15.2.rst

+49-13
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,61 @@ API changes
2424
- Indexing in ``MultiIndex`` beyond lex-sort depth is now supported, though
2525
a lexically sorted index will have a better performance. (:issue:`2646`)
2626

27-
.. ipython:: python
28-
:okexcept:
29-
:okwarning:
27+
.. code-block:: ipython
28+
29+
In [1]: df = pd.DataFrame({'jim':[0, 0, 1, 1],
30+
...: 'joe':['x', 'x', 'z', 'y'],
31+
...: 'jolie':np.random.rand(4)}).set_index(['jim', 'joe'])
32+
...:
3033
31-
df = pd.DataFrame({'jim':[0, 0, 1, 1],
32-
'joe':['x', 'x', 'z', 'y'],
33-
'jolie':np.random.rand(4)}).set_index(['jim', 'joe'])
34-
df
35-
df.index.lexsort_depth
34+
In [2]: df
35+
Out[2]:
36+
jolie
37+
jim joe
38+
0 x 0.126970
39+
x 0.966718
40+
1 z 0.260476
41+
y 0.897237
42+
43+
[4 rows x 1 columns]
44+
45+
In [3]: df.index.lexsort_depth
46+
Out[3]: 1
3647
3748
# in prior versions this would raise a KeyError
3849
# will now show a PerformanceWarning
39-
df.loc[(1, 'z')]
50+
In [4]: df.loc[(1, 'z')]
51+
Out[4]:
52+
jolie
53+
jim joe
54+
1 z 0.260476
55+
56+
[1 rows x 1 columns]
4057
4158
# lexically sorting
42-
df2 = df.sort_index()
43-
df2
44-
df2.index.lexsort_depth
45-
df2.loc[(1,'z')]
59+
In [5]: df2 = df.sort_index()
60+
61+
In [6]: df2
62+
Out[6]:
63+
jolie
64+
jim joe
65+
0 x 0.126970
66+
x 0.966718
67+
1 y 0.897237
68+
z 0.260476
69+
70+
[4 rows x 1 columns]
71+
72+
In [7]: df2.index.lexsort_depth
73+
Out[7]: 2
74+
75+
In [8]: df2.loc[(1,'z')]
76+
Out[8]:
77+
jolie
78+
jim joe
79+
1 z 0.260476
80+
81+
[1 rows x 1 columns]
4682
4783
- Bug in unique of Series with ``category`` dtype, which returned all categories regardless
4884
whether they were "used" or not (see :issue:`8559` for the discussion).

0 commit comments

Comments
 (0)