-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Add examples to .get_loc methods #17563
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: Add examples to .get_loc methods #17563
Conversation
944aa9b
to
46159be
Compare
Codecov Report
@@ Coverage Diff @@
## master #17563 +/- ##
==========================================
- Coverage 91.25% 91.23% -0.02%
==========================================
Files 163 163
Lines 49617 49617
==========================================
- Hits 45277 45268 -9
- Misses 4340 4349 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17563 +/- ##
==========================================
- Coverage 91.25% 91.23% -0.02%
==========================================
Files 163 163
Lines 49617 49617
==========================================
- Hits 45277 45268 -9
- Misses 4340 4349 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17563 +/- ##
==========================================
- Coverage 91.19% 91.18% -0.02%
==========================================
Files 163 163
Lines 49626 49626
==========================================
- Hits 45258 45249 -9
- Misses 4368 4377 +9
Continue to review full report at Codecov.
|
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.
Thanks! added some comments
pandas/core/indexes/base.py
Outdated
@Appender(_index_shared_docs['get_loc']) | ||
Examples | ||
--------- | ||
>>> unique_index = pd.%(klass)s(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 don't think 'klass' substitution is needed for the example, just show it with base Index, logic of behaviour should be the same for all types (for other types of Index subclasses the 'abc' values might not be valid anyhow, and you get a 'wrong' example)
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
pandas/core/indexes/interval.py
Outdated
Parameters | ||
---------- | ||
key : label | ||
method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional |
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 tlist the other methods, as you say they are not implemented (like you did in the categorical docstring)
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
>>> i3 = pd.Interval(0, 2) | ||
>>> overlapping_index = pd.IntervalIndex.from_intervals([i2, i3]) | ||
>>> overlapping_index.get_loc(1.5) | ||
array([0, 1], dtype=int64) |
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.
We are discussing to change this behaviour, but the above is still correct on master. However, I would change the example to already add get_loc(Interval(..))
cases (the case we intent to keep working, the scalar numerical value might raise in the future). So that way we can just remove those case that will not be valid anymore, but keep the exact match for actual Interval objects 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.
Added an interval example
pandas/core/indexes/multi.py
Outdated
-------- | ||
Index.get_loc : get_loc method for (single-level) index. | ||
get_locs : Given a tuple of slices/lists/labels/boolean indexer to a | ||
level-wise spec, produce an indexer to extract those locations |
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.
extra level of indentation here
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
pandas/core/indexes/category.py
Outdated
@@ -354,7 +354,7 @@ def _to_safe_for_reshape(self): | |||
|
|||
def get_loc(self, key, method=None): | |||
""" | |||
Get integer location for requested label | |||
Get integer location for requested label. |
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 actually like the "Get integer location, slice or boolean mask for requested label" from the multi-index docstring, as this seems to be more complete description?
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 agree, Will change
pandas/core/indexes/base.py
Outdated
>>> monotonic_index = pd.%(klass)s(list('abbc')) | ||
>>> monotonic_index.get_loc('b') | ||
slice(1, 3, None) | ||
>>> non_monotonic_index = pd.%(klass)s(list('abcb')) |
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.
put a blank line in-between cases
pandas/core/indexes/multi.py
Outdated
-------- | ||
Index.get_loc : get_loc method for (single-level) index. | ||
get_locs : Given a tuple of slices/lists/labels/boolean indexer to a | ||
level-wise spec, produce an indexer to extract those locations |
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 think you need to indent this (to the :
)
46159be
to
8c9839f
Compare
I think you still need to use the |
8c9839f
to
ed372a2
Compare
Hello @topper-123! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on September 20, 2017 at 14:58 Hours UTC |
I've made various changes.The @appender is still there, though the examples are in it as well. The EDIT: Are you sure it's ok to force-push changes to the same commit? To me it seems that it makes reviewting more difficult, as the connection between code and comments seems to get lost. |
0c9094d
to
0ab5488
Compare
The error is at So the error seems to be unrelated to my pull request... |
if commits are logical / organized and have good messages, yes. however most commits I see should just be combined into 1 and promote even more confusion. rebasing is also much easier with fewer commits. so force pushing is fine as its your own fork. |
looks fine. can you rebase and push again to force ci to run. |
For that reason in general I prefer to add commits instead of rebasing/force push, but to clean up messed up github state, it is perfectly fine (as long as it is in a branch). |
0ab5488
to
28c9c89
Compare
Green @jreback |
@topper-123 Thanks! |
git diff upstream/master -u -- "*.py" | flake8 --diff
This pull request adds some examples to
.get_loc
doc string ofpd.Index
,pd.CategoricalIndex
,pd.MultiIndex
&pd.IntervalIndex
. Also clarifies the return value in some cases.I previously proposed pull request #17380, but the commit history there became a mess. I've deleted that pull request and added this instead.