Skip to content

DOC: Clarify that 'names' is only used when constructing a MultiIndex #61619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those seem like a test more than an example. And I don't see names as a parameter of Index: https://pandas.pydata.org/docs/dev/reference/indexing.html#index

I guess the issue is outdated, it's from 2018, and last comment confirms.

True
"""


# similar to __array_priority__, positions Index after Series and DataFrame
# but before ExtensionArray. Should NOT be overridden by subclasses.
__pandas_priority__ = 2000
Expand Down
Loading