-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC/TST: Series.reorder_levels() can take names; added tests #5573
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
Are there any tests for reorder_levels, I can't see any in test_series ? We should test if adding to docstring. :s Would you mind adding some tests to confirm this behaviour to this PR? |
Is it the same for a DataFrame? Then the docstring there could be changed also. |
maybe repush this? Looks like a Travis hiccup |
I'll look at those two points and repush later tonight/tomorrow. On Nov 22, 2013, at 5:39 PM, "Jeff Tratner" <[email protected]mailto:[email protected]> wrote: maybe repush this? Looks like a Travis hiccup — |
I'm not seeing any tests for this in series/frame/generic. I'll write a set. Also, does this seems odd to anyone else, given the name? In [40]: s.reorder_levels([2, 2, 2])
Out[40]:
0 0 0 0
1 1 1 1
0 0 0 2
1 1 1 3
0 0 0 4
1 1 1 5
dtype: int64 I would have expected it to check that it's an actual reordering. |
Hmm, this also isn't great: In [66]: s
Out[66]:
L1 L2 L2 # Note the non unique index names
bar one 0 0
two 1 1
three 0 2
one 1 3
two 0 4
three 1 5
dtype: int64
In [68]: s.reorder_levels(['L2', 'L1', 'L2'])
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-68-3ed0635cff91> in <module>()
----> 1 s.reorder_levels(['L2', 'L1', 'L2'])
/Users/tom/Envs/pandas-dev/lib/python2.7/site-packages/pandas-0.12.0_993_gda89834-py2.7-macosx-10.8-x86_64.egg/pandas/core/series.pyc in reorder_levels(self, order)
1846
1847 result = self.copy()
-> 1848 result.index = result.index.reorder_levels(order)
1849 return result
1850
/Users/tom/Envs/pandas-dev/lib/python2.7/site-packages/pandas-0.12.0_993_gda89834-py2.7-macosx-10.8-x86_64.egg/pandas/core/index.pyc in reorder_levels(self, order)
2698 ----------
2699 """
-> 2700 order = [self._get_level_number(i) for i in order]
2701 if len(order) != self.nlevels:
2702 raise AssertionError(('Length of order must be same as '
/Users/tom/Envs/pandas-dev/lib/python2.7/site-packages/pandas-0.12.0_993_gda89834-py2.7-macosx-10.8-x86_64.egg/pandas/core/index.pyc in _get_level_number(self, level)
2185 except ValueError:
2186 if not isinstance(level, int):
-> 2187 raise KeyError('Level %s not found' % str(level))
2188 elif level < 0:
2189 level += self.nlevels
KeyError: 'Level L2 not found' Raising an error is the right behavior, but the message could be better. Separate PR though! |
Thanks for looking into this, do you want us to merge (before sep PR) ? |
I said nothing about me doing a separate PR :) I won't be able to get to it today. I think this ones good to go. |
@TomAugspurger dang, too slow, looks like it needs a rebase :( |
I'll try later tonight hopefully. Before the rc maintenance branch is opened at least. On Nov 23, 2013, at 10:23 PM, "Andy Hayden" <[email protected]mailto:[email protected]> wrote: @TomAugspurgerhttps://github.com/TomAugspurger dang, too slow, looks like it needs a rebase :( — |
TST: reorder was untested DOC/TST reorder_levels takes names
rebased and repushed. The conflict was just on the docstring. |
DOC/TST: Series.reorder_levels() can take names; added tests
Minor change to the docstring. It said you must refer to the position (not keys). Keys work: