Skip to content

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

Merged
merged 3 commits into from
Sep 6, 2017

Conversation

topper-123
Copy link
Contributor

  • closes #xxxx
  • [x ] tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

I've added examples to MultiIndex.get_level_values. Also I've done some related changes:

  • made return value of Index._get_level_values
  • Added test for when supplying name to Index._get_level_values. The method could always take level name, but the doc said only integer could be supplied.

@pep8speaks
Copy link

pep8speaks commented Sep 1, 2017

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

@codecov
Copy link

codecov bot commented Sep 1, 2017

Codecov Report

Merging #17414 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.92% <ø> (ø) ⬆️
#single 40.25% <ø> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/base.py 96.29% <ø> (ø) ⬆️
pandas/core/indexes/multi.py 96.9% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️
pandas/core/indexes/datetimes.py 95.43% <0%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1981b67...cc67b9a. Read the comment docs.

@gfyoung gfyoung added Docs Testing pandas testing functions or related to the test suite labels Sep 2, 2017

Parameters
----------
level : int
level : int or level name
Copy link
Member

@gfyoung gfyoung Sep 2, 2017

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.

Copy link
Contributor Author

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

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...

Copy link
Contributor Author

@topper-123 topper-123 Sep 2, 2017

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.


Returns
-------
values : Index
self : Index
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

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

Choose a reason for hiding this comment

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

Reference your PR here.


Returns
-------
values : Index

Examples
Copy link
Contributor Author

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

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.


Returns
-------
values : Index
Because there is only one level when the index has one level,
the return value is always self in this case.
Copy link
Member

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thats better

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

@gfyoung gfyoung Sep 2, 2017

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.

@jreback jreback added this to the 0.21.0 milestone Sep 6, 2017
@jreback
Copy link
Contributor

jreback commented Sep 6, 2017

lgtm. @gfyoung unless you had any more comments, merge away.

@gfyoung gfyoung merged commit d457791 into pandas-dev:master Sep 6, 2017
@gfyoung
Copy link
Member

gfyoung commented Sep 6, 2017

Thanks @topper-123 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs MultiIndex Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants