-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Add support to names keyword in Index #28032
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
Conversation
pandas/core/indexes/base.py
Outdated
@@ -259,12 +261,22 @@ def __new__( | |||
dtype=None, | |||
copy=False, | |||
name=None, | |||
names=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to the end (before kwargs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this!
fastpath=None, | ||
tupleize_cols=True, | ||
**kwargs | ||
): | ||
|
||
if name is None and hasattr(data, "name"): | ||
if names is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super familiar with this part of the code but is it possible to share the length of checking of names
across the index types? This already fails for a MultiIndex:
>>> pd.MultiIndex.from_tuples((('a', 'b'), ('c', 'd')), names=('a', 'b', 'c'))
ValueError: Length of names must match number of levels in MultiIndex.
So ideally could share that machinery here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a 100% sure I understood what you're saying here, but I removed the check for weather the data is a list-like.
Is that it?
Hey @WillAyd I did some changes related to what you've commented, that being said, I'm not a 100% sure that I've understood your second comment. |
To clarify my comment it looks like code has been added here to validate the Would there be a way to align those? With that said I'm a little hesitant on this change. I understand the goal but it feels weird to have both a |
I'd say that's an issue with the |
I assume that's just because the Index constructor appears to accept anything though, right? Not necessarily that it's valid. >>> pd.Index([], name="foo")
Index([], dtype='object', name=['foo'])
>>> pd.Index([], names=["foo"])
Index([], dtype='object')
>>> pd.Index([], something="foo")
Index([], dtype='object') |
It's used if you take the MultiIndex route In [5]: pd.Index([(1, 2), (3, 4)], names=['a', 'b'], tupleize_cols=True)
Out[5]:
MultiIndex([(1, 2),
(3, 4)],
names=['a', 'b']) |
Sorry I think I went in a circle but coming back to it...I don't see how having both |
closing; we want to deprecate names I think, this is going backwards. |
names
names argument, doesn't set index name #19082black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff