Skip to content

Commit d597079

Browse files
DOC: Update MultiIndex.take and MultiIndex.repeat docstring examples to use MultiIndex (#62809)
1 parent 674e619 commit d597079

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

pandas/core/indexes/multi.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,9 +2337,18 @@ def take(
23372337
23382338
Examples
23392339
--------
2340-
>>> idx = pd.Index(["a", "b", "c"])
2341-
>>> idx.take([2, 2, 1, 2])
2342-
Index(['c', 'c', 'b', 'c'], dtype='str')
2340+
>>> idx = pd.MultiIndex.from_arrays([["a", "b", "c"], [1, 2, 3]])
2341+
>>> idx
2342+
MultiIndex([('a', 1),
2343+
('b', 2),
2344+
('c', 3)],
2345+
)
2346+
>>> idx.take([2, 2, 1, 0])
2347+
MultiIndex([('c', 3),
2348+
('c', 3),
2349+
('b', 2),
2350+
('a', 1)],
2351+
)
23432352
"""
23442353
nv.validate_take((), kwargs)
23452354
indices = ensure_platform_int(indices)
@@ -2525,13 +2534,28 @@ def repeat(self, repeats: int, axis=None) -> MultiIndex:
25252534
25262535
Examples
25272536
--------
2528-
>>> idx = pd.Index(["a", "b", "c"])
2537+
>>> idx = pd.MultiIndex.from_arrays([["a", "b", "c"], [1, 2, 3]])
25292538
>>> idx
2530-
Index(['a', 'b', 'c'], dtype='object')
2539+
MultiIndex([('a', 1),
2540+
('b', 2),
2541+
('c', 3)],
2542+
)
25312543
>>> idx.repeat(2)
2532-
Index(['a', 'a', 'b', 'b', 'c', 'c'], dtype='object')
2544+
MultiIndex([('a', 1),
2545+
('a', 1),
2546+
('b', 2),
2547+
('b', 2),
2548+
('c', 3),
2549+
('c', 3)],
2550+
)
25332551
>>> idx.repeat([1, 2, 3])
2534-
Index(['a', 'b', 'b', 'c', 'c', 'c'], dtype='object')
2552+
MultiIndex([('a', 1),
2553+
('b', 2),
2554+
('b', 2),
2555+
('c', 3),
2556+
('c', 3),
2557+
('c', 3)],
2558+
)
25352559
"""
25362560
nv.validate_repeat((), {"axis": axis})
25372561
# error: Incompatible types in assignment (expression has type "ndarray",

0 commit comments

Comments
 (0)