-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the Index.get_level_values docstring #20210
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
DOC: update the Index.get_level_values docstring #20210
Conversation
pandas/core/indexes/base.py
Outdated
``level`` is either the integer position of the level in the | ||
MultiIndex, or the name of the level. | ||
It is either the integer position of the level in the | ||
MultiIndex, or the `name` of the level. |
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.
Don't think name has to be in backticks, since it isn't a parameter
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.
Since MultiIndex has its own docstring, you probably don't have to reference it here.
pandas/core/indexes/base.py
Outdated
It is either the integer position of the level in the | ||
MultiIndex, or the `name` of the level. | ||
If given as an integer, it must be between 0 and the | ||
number of levels. |
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.
Number of levels - 1?
pandas/core/indexes/base.py
Outdated
Examples | ||
--------- | ||
|
||
Create an 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.
Probalby don't need this line. I'd remove it and add a line showing idx
pandas/core/indexes/base.py
Outdated
|
||
Create a MultiIndex: | ||
|
||
>>> mi = pd.MultiIndex.from_arrays((list('abc'), list('def'))) |
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.
can pass names=
to from_arrays
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.
Although line wrapping would be needed and this case and it would still end up in two lines, which isn't as nice in my opinion. Although I'll change it as you've requested.
pandas/core/indexes/base.py
Outdated
@@ -2788,26 +2788,55 @@ def set_value(self, arr, key, value): | |||
|
|||
def _get_level_values(self, level): | |||
""" | |||
Return an Index of values for requested level. | |||
|
|||
Return an Index of values for requested level, equal to the length |
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 add that this is mainly for compatibility with MultiIndex.
Reading through this, it may make sense to say that this isn't very useful for non-MultiIndex indexes. A small example should be OK, but the most important bit is the See Also to MultiIndex.get_level_values. |
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.
Very good, I would just make it clear in the summary and extended summary that this method is specially useful to deal with MultiIndex.
pandas/core/indexes/base.py
Outdated
@@ -2788,26 +2788,55 @@ def set_value(self, arr, key, value): | |||
|
|||
def _get_level_values(self, level): | |||
""" | |||
Return an Index of values for requested level. |
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.
Return an Index of values for requested level. --> Return an Index of values for requested level, specially useful for MultiIndex.
It is important to make it clear somehow that this is most useful when dealing with a MultiIndex.
pandas/core/indexes/base.py
Outdated
|
||
Notes | ||
--------- | ||
For `Index`, level should be 0, since there are no multiple levels. |
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.
no backticks
pandas/core/indexes/base.py
Outdated
Create an Index: | ||
|
||
>>> idx = pd.Index(list('abc')) | ||
|
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 wouldn't bother show this for an 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.
Please elaborate what kind of change you would like to us to make. MultiIndex already mentions the other example. In our view, working on an Index is also useful to see for users somewhere, and this would be a proper place for it.
90e6b68
to
fe2f525
Compare
Most of the notes have been addressed and force pushed. |
pandas/core/indexes/base.py
Outdated
@@ -2788,26 +2788,45 @@ def set_value(self, arr, key, value): | |||
|
|||
def _get_level_values(self, level): | |||
""" | |||
Return an Index of values for requested level, specially useful for |
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.
need to be 1 line. you can remove after the comma.
pandas/core/indexes/base.py
Outdated
|
||
Notes | ||
--------- |
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.
make the same length as Notes
pandas/core/indexes/base.py
Outdated
@@ -2788,26 +2788,45 @@ def set_value(self, arr, key, value): | |||
|
|||
def _get_level_values(self, level): | |||
""" | |||
Return an Index of values for requested level, specially useful for | |||
MultiIndex. | |||
|
|||
Return an Index of values for requested level, equal to the length |
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.
This is pretty repetitive with the summary. I think just the bit about MultiIndex is useful.
The is primarily useful to get an individual level of values from a MultiIndex,
but is provided on Index as well for compatability.
pandas/core/indexes/base.py
Outdated
``level`` is either the integer position of the level in the | ||
MultiIndex, or the name of the level. | ||
It is either the integer position or the name of the level. | ||
If given as an integer, it must be between 0 and the |
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.
Ah this isn't quite right. Negative indices are accepted as well. Probably OK to just remove the second sentence, as to most Python programmers, "integer position" is clear enough.
pandas/core/indexes/base.py
Outdated
>>> idx | ||
Index(['a', 'b', 'c'], dtype='object') | ||
|
||
Get level value by supplying level as integer: |
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.
backtick around `level`. Add "an" between "as integer"
@bkil-syslogng Do you have time to update the PR based on the last comments? |
…ating_Index.get_level_values_docstring
Codecov Report
@@ Coverage Diff @@
## master #20210 +/- ##
=========================================
Coverage ? 91.72%
=========================================
Files ? 150
Lines ? 49162
Branches ? 0
=========================================
Hits ? 45096
Misses ? 4066
Partials ? 0
Continue to review full report at Codecov.
|
Rebased and added final fixes. @bkil-syslogng Thanks! |
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks: