Skip to content

ENH add level argument to set_names, set_levels and set_labels (GH7792) #7874

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

Merged
merged 1 commit into from
Jul 30, 2014

Conversation

mtrbean
Copy link
Contributor

@mtrbean mtrbean commented Jul 29, 2014

Closes #7792

New level argument:

set_names(self, names, level=None, inplace=False)
set_levels(self, levels, level=None, inplace=False, verify_integrity=True)
set_labels(self, labels, level=None, inplace=False, verify_integrity=True)

e.g.
set_names('foo',level=1)
set_names(['foo','bar'],level=[1,2])
set_levels(['a','b','c'],level=1)
set_levels([['a','b','c'],[1,2,3]],level=[1,2])

@@ -1509,15 +1511,30 @@ def test_set_names_and_rename(self):
self.assertIsNone(res)
self.assertEqual(ind.names, new_names2)

def test_set_levels_and_set_labels(self):
# set names for specific level
ind = self.index.set_names(new_names[0], level=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

pls add the issue reference here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry it is my first PR. Are you expecting a reference to GH7792 as a comment in the code or in the commit message?

If you are specifically talking about the apparent removal of the test test_set_levels_and_set_labels(), the reason it that the test became too long so I split it into two: test_set_levels() and test_set_labels()

Copy link
Contributor

Choose a reason for hiding this comment

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

hah...pretty good for your first PR! yes I mean just put in a comment (and the commit), the issue reference.

@mtrbean mtrbean changed the title ENH7792 add optional level argument to set_names(), set_levels() and set... ENH add level argument to set_names, set_levels and set_labels (GH7792) Jul 30, 2014
@mtrbean
Copy link
Contributor Author

mtrbean commented Jul 30, 2014

Added tests for the reverse (len(levels) == 2 but level =1)

# side note - you probably wouldn't want to use levels and labels
# directly like this - but it is possible.
levels, labels = self.index.levels, self.index.labels
new_levels = [[lev + 'a' for lev in level] for level in levels]
major_labels, minor_labels = labels
Copy link
Contributor

Choose a reason for hiding this comment

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

did these do something

nvm, I see you just moved them

@jreback jreback added this to the 0.15.0 milestone Jul 30, 2014
@jreback
Copy link
Contributor

jreback commented Jul 30, 2014

look good

@jreback jreback merged commit 9da121e into pandas-dev:master Jul 30, 2014
@jreback
Copy link
Contributor

jreback commented Jul 30, 2014

thanks! this is a nice enhancement

@mtrbean mtrbean deleted the API-7792 branch July 30, 2014 22:38
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.

API: enable set_levels/set_names/set_labels to accept a list and a level argument to change a single level/value
2 participants