-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC/TST: Add examples to MultiIndex.get_level_values + related changes #17414
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
Hello @topper-123! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on September 02, 2017 at 12:40 Hours UTC |
61adbe9
to
630b664
Compare
Codecov Report
@@ Coverage Diff @@
## master #17414 +/- ##
==========================================
- Coverage 91.15% 91.14% -0.02%
==========================================
Files 163 163
Lines 49581 49581
==========================================
- Hits 45198 45190 -8
- Misses 4383 4391 +8
Continue to review full report at Codecov.
|
pandas/core/indexes/base.py
Outdated
|
||
Parameters | ||
---------- | ||
level : int | ||
level : int or level name |
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.
The general format is to specify the data type on the first line followed by an explanation of their semantics in a subsequent block.
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.
Ok, I've changed this, also for MultiIndex.
@@ -2529,15 +2529,20 @@ def set_value(self, arr, key, value): | |||
def _get_level_values(self, level): | |||
""" | |||
Return an Index of values for requested level, equal to the length | |||
of the index | |||
of the index. |
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 Blocking : I would really like if we could condense this into one line (doc-string convention), but it's hard to see ATM what to remove from this...
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 haven't got a better proposal either.
pandas/core/indexes/base.py
Outdated
|
||
Returns | ||
------- | ||
values : Index | ||
self : Index |
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.
You aren't returning self
are you? I would leave this line alone and instead add a line below explaining what the output is.
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.
Actually it is returning self. this method probably meant to make the API the same for MultiIndex and other Index types, so for Index types this really doesn't do much. The name values
is used for MultiIndex, but isn't used here...
should I still change it?
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.
@topper-123 : Sorry, I wasn't able to check the actual file on my phone. Yes, you are correct that self
is returned. While I do stand corrected, I do think leaving it unchanged is preferable for consistency. You can however, in a line beneath that explain that values
in this implementation is just self
because there is only one level.
pandas/tests/indexes/test_base.py
Outdated
@@ -1438,6 +1438,12 @@ def test_get_level_values(self): | |||
result = self.strIndex.get_level_values(0) | |||
tm.assert_index_equal(result, self.strIndex) | |||
|
|||
# test with name |
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.
Reference your PR here.
e9aa20b
to
01f792b
Compare
01f792b
to
8bfeec3
Compare
pandas/core/indexes/multi.py
Outdated
|
||
Returns | ||
------- | ||
values : Index | ||
|
||
Examples |
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.
Note that I've made the examples a bit simpler. No need to demonstrate CategoricalIndex etc. here...
level : int or level name | ||
level : int or str | ||
``level`` is either the integer position of the level in the | ||
MultiIndex, or the name of the level. | ||
|
||
Returns | ||
------- | ||
values : Index |
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.
Let's explain what values
is here since you are updating the docs.
pandas/core/indexes/base.py
Outdated
|
||
Returns | ||
------- | ||
values : Index | ||
Because there is only one level when the index has one level, | ||
the return value is always self in this case. |
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 would simplify to just:
"self, as there is only one level in the Index"
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.
Yes, thats better
pandas/tests/indexes/test_base.py
Outdated
@@ -1438,6 +1438,12 @@ def test_get_level_values(self): | |||
result = self.strIndex.get_level_values(0) | |||
tm.assert_index_equal(result, self.strIndex) | |||
|
|||
# GH 17414 |
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.
You didn't need to necessarily remove your other note. I was suggesting that you just add a reference to the issue somewhere in the comments.
1f3b7ed
to
e62dc50
Compare
e62dc50
to
cc67b9a
Compare
lgtm. @gfyoung unless you had any more comments, merge away. |
Thanks @topper-123 ! |
git diff upstream/master -u -- "*.py" | flake8 --diff
I've added examples to
MultiIndex.get_level_values
. Also I've done some related changes:Index._get_level_values
Index._get_level_values
. The method could always take level name, but the doc said only integer could be supplied.