From 6841363f30c628bf3c732aebc64f512e17225e20 Mon Sep 17 00:00:00 2001 From: EdwardPunzalan <107876272+EdwardPunzalan@users.noreply.github.com> Date: Mon, 9 Jun 2025 23:09:39 -0400 Subject: [PATCH] DOC: Clarify that 'names' is only used when constructing a MultiIndex --- pandas/core/indexes/base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 4e1ea07907cdb..c64415cf9e53b 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -362,6 +362,9 @@ class Index(IndexOpsMixin, PandasObject): An Index instance can **only** contain hashable objects. An Index instance *can not* hold numpy float16 dtype. + The `names` argument is only relevant when the data results in a `MultiIndex`. + When constructing a regular `Index`, use `name=` to assign a name. Passing `names=` will have no effect unless a `MultiIndex` is created. + Examples -------- >>> pd.Index([1, 2, 3]) @@ -372,8 +375,15 @@ class Index(IndexOpsMixin, PandasObject): >>> pd.Index([1, 2, 3], dtype="uint8") Index([1, 2, 3], dtype='uint8') + + >>> pd.Index([], name='a').name + 'a' + + >>> pd.Index([], names=['a']).name is None + True """ + # similar to __array_priority__, positions Index after Series and DataFrame # but before ExtensionArray. Should NOT be overridden by subclasses. __pandas_priority__ = 2000