From fed99349f889e2a40e8e814a3d44afdc3bcb8ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E7=9F=A5=E6=81=92?= <1197843831@qq.com> Date: Fri, 24 Oct 2025 00:26:18 +0800 Subject: [PATCH] DOC: Update MultiIndex.take and MultiIndex.repeat docstring examples to use MultiIndex --- pandas/core/indexes/multi.py | 38 +++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 9819f3e2e09a4..1cc1928136da1 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -2337,9 +2337,18 @@ def take( Examples -------- - >>> idx = pd.Index(["a", "b", "c"]) - >>> idx.take([2, 2, 1, 2]) - Index(['c', 'c', 'b', 'c'], dtype='str') + >>> idx = pd.MultiIndex.from_arrays([["a", "b", "c"], [1, 2, 3]]) + >>> idx + MultiIndex([('a', 1), + ('b', 2), + ('c', 3)], + ) + >>> idx.take([2, 2, 1, 0]) + MultiIndex([('c', 3), + ('c', 3), + ('b', 2), + ('a', 1)], + ) """ nv.validate_take((), kwargs) indices = ensure_platform_int(indices) @@ -2525,13 +2534,28 @@ def repeat(self, repeats: int, axis=None) -> MultiIndex: Examples -------- - >>> idx = pd.Index(["a", "b", "c"]) + >>> idx = pd.MultiIndex.from_arrays([["a", "b", "c"], [1, 2, 3]]) >>> idx - Index(['a', 'b', 'c'], dtype='object') + MultiIndex([('a', 1), + ('b', 2), + ('c', 3)], + ) >>> idx.repeat(2) - Index(['a', 'a', 'b', 'b', 'c', 'c'], dtype='object') + MultiIndex([('a', 1), + ('a', 1), + ('b', 2), + ('b', 2), + ('c', 3), + ('c', 3)], + ) >>> idx.repeat([1, 2, 3]) - Index(['a', 'b', 'b', 'c', 'c', 'c'], dtype='object') + MultiIndex([('a', 1), + ('b', 2), + ('b', 2), + ('c', 3), + ('c', 3), + ('c', 3)], + ) """ nv.validate_repeat((), {"axis": axis}) # error: Incompatible types in assignment (expression has type "ndarray",