Skip to content
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

ENH: Add Series.set_index #27504

Closed
wants to merge 2 commits into from
Closed

ENH: Add Series.set_index #27504

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 21, 2019

Help users method-chain all the things. This is modeled closely on the original support for Arrays added in 2011 by Wes Mckinney in

553bacc ENH: can pass external arrays in lieu of column names to DataFrame.set_index

This is also how DataFrame.set_index behaves (though poorly documented), modulo support for column keys which don't apply here.

related discussion #24046, and end of #14829 (comment), #12392

@WillAyd
Copy link
Member

WillAyd commented Jul 21, 2019

I think this has the same issue as the previous PR where the semantics for a Series now break from a DataFrame as the former here accepts list-likes whereas the latter is used for labels.

Haven't kept totally current on this - was this approach ever agreed to in one of the issues or are you just submitting to restart conversation?

@WillAyd
Copy link
Member

WillAyd commented Jul 21, 2019

So to maybe get you up to speed here the semantics of this PR would differ from a DataFrame. Taking your first test case this:

# Sets the index as "A", "B", "C"
>>> pd.Series(range(3)).set_index(["A", "B", "C"])
A    0
B    1
C    2
dtype: int64

Would exhibit different behavior than what happens on a DataFrame with the same number of rows

# Selects columns "A", "B", "C" and moves to the index
>>> pd.DataFrame(np.ones((3,3)), columns=list('ABC')).set_index(["A", "B", "C"])
Empty DataFrame
Columns: []
Index: [(1.0, 1.0, 1.0), (1.0, 1.0, 1.0), (1.0, 1.0, 1.0)]

So in a vacuum this PR would make sense but given the current state of things would need to have something additional to bridge behavior between the two object types.

@pep8speaks
Copy link

pep8speaks commented Jul 24, 2019

Hello @pilkibun! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-07-25 04:17:23 UTC

@ghost
Copy link
Author

ghost commented Jul 31, 2019

This is very contentious issue among the maintainers it seems, and considering how #22225 ended, seems unlikely this is going anywhere.

@ghost ghost closed this Jul 31, 2019
@ghost ghost deleted the series_set_index branch July 31, 2019 14:16
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: add Series.set_index
2 participants