Skip to content

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

Closed
wants to merge 4 commits into from

Conversation

pedrocunial
Copy link

@pedrocunial pedrocunial commented Aug 20, 2019

@@ -259,12 +261,22 @@ def __new__(
dtype=None,
copy=False,
name=None,
names=None,
Copy link
Member

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)

Copy link
Author

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:
Copy link
Member

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

Copy link
Author

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?

@pedrocunial
Copy link
Author

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.

@WillAyd
Copy link
Member

WillAyd commented Aug 27, 2019

To clarify my comment it looks like code has been added here to validate the names argument when called as part of the Index constructor. However, there also appears to be validation as part of the MultiIndex constructor (at least from an end user perspective - haven't dug deep in code).

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 name and names argument as part of the constructor. Have to think through in more detail

@WillAyd WillAyd added API Design Index Related to the Index class or subclasses Needs Discussion Requires discussion from core team before further action labels Aug 27, 2019
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Sep 6, 2019

With that said I'm a little hesitant on this change. I understand the goal but it feels weird to have both a name and names argument as part of the constructor.

I'd say that's an issue with the Index constructor's API. They're both valid arguments, this just updating the signature / docs to reflect that :)

@WillAyd
Copy link
Member

WillAyd commented Sep 6, 2019

They're both valid arguments, this just updating the signature / docs to reflect that :)

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')

@TomAugspurger
Copy link
Contributor

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'])

@WillAyd
Copy link
Member

WillAyd commented Sep 6, 2019

Sorry I think I went in a circle but coming back to it...I don't see how having both name and names makes sense from an API perspective. I get we want to do that to achieve symmetry in our inheritance but from an end user perspective this feels like a step in the wrong direction

@jreback
Copy link
Contributor

jreback commented Oct 3, 2019

closing; we want to deprecate names I think, this is going backwards.

@jreback jreback closed this Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Index Related to the Index class or subclasses Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Creating Index name using names names argument, doesn't set index name
4 participants