Skip to content

Commit 6841363

Browse files
DOC: Clarify that 'names' is only used when constructing a MultiIndex
1 parent b8371f5 commit 6841363

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pandas/core/indexes/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ class Index(IndexOpsMixin, PandasObject):
362362
An Index instance can **only** contain hashable objects.
363363
An Index instance *can not* hold numpy float16 dtype.
364364
365+
The `names` argument is only relevant when the data results in a `MultiIndex`.
366+
When constructing a regular `Index`, use `name=` to assign a name. Passing `names=` will have no effect unless a `MultiIndex` is created.
367+
365368
Examples
366369
--------
367370
>>> pd.Index([1, 2, 3])
@@ -372,8 +375,15 @@ class Index(IndexOpsMixin, PandasObject):
372375
373376
>>> pd.Index([1, 2, 3], dtype="uint8")
374377
Index([1, 2, 3], dtype='uint8')
378+
379+
>>> pd.Index([], name='a').name
380+
'a'
381+
382+
>>> pd.Index([], names=['a']).name is None
383+
True
375384
"""
376385

386+
377387
# similar to __array_priority__, positions Index after Series and DataFrame
378388
# but before ExtensionArray. Should NOT be overridden by subclasses.
379389
__pandas_priority__ = 2000

0 commit comments

Comments
 (0)