-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Added examples to pd.Index.get_loc #17380
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: Added examples to pd.Index.get_loc #17380
Conversation
Hello @topper-123! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on September 01, 2017 at 14:02 Hours UTC |
f145027
to
f03c140
Compare
Codecov Report
@@ Coverage Diff @@
## master #17380 +/- ##
==========================================
- Coverage 91.01% 90.99% -0.02%
==========================================
Files 163 163
Lines 49570 49570
==========================================
- Hits 45116 45107 -9
- Misses 4454 4463 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17380 +/- ##
==========================================
- Coverage 91.04% 90.99% -0.05%
==========================================
Files 163 163
Lines 49581 49581
==========================================
- Hits 45139 45118 -21
- Misses 4442 4463 +21
Continue to review full report at Codecov.
|
pandas/core/indexes/base.py
Outdated
>>> unique_index = pd.Index(list('abc')) | ||
>>> unique_index.get_loc('b') | ||
1 | ||
>>> monotonic_index = pd.Index(list('abbc')) |
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 you add a blank line between cases
lgtm. ping push / green. |
f03c140
to
0f16e2e
Compare
ping |
@jreback Is this ok? (More of a general question): I force-pushed the change, is that ok or is it considered "bad form"? Edit: I made a last-minute update so sub-class name will displayed properly (e.g. CategoricalIndex). |
21d2a5f
to
2c098cd
Compare
Enabled tests that currently aren't running. Small fix to make sure all tests pass. Verified that the raised messages match expectations for TestToDatetimeUnit::test_frame.
* implemented fix for GH issue pandas-dev#16953 * added tests for fix of issue pandas-dev#16953 * changed comments for git issue to pandas style GH# * changed linelength in tests, so all lines are less than 80 characters * added whatsnew entry * swaped conversion and filtering of values, for plot to also work with object dtypes * refomated code, so len(line) < 80 * changed whatsnew with timedelta and datetime dtypes * added support for datetimetz and extended tests * added reason to pytest.mark.xfail
…s with pyarrow < 0.6.0 (pandas-dev#17447) closes pandas-dev#17438
@topper-123 force pushing to your own branch is just fine and in-fact necessary after rebasing. |
pandas/core/indexes/base.py
Outdated
|
||
Examples | ||
--------- | ||
>>> unique_index = pd.%(target_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.
hmm these are only valid for Index/CategoricalIndex. Do these examples show up for other indexes (IIR we are using this combined doc-string for all sub-classes). You'll have to do this as an additional @Appender
to those classes only.
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 I will do this all over again. Many of the .get_loc
methods are subtlely different, so it's difficult to have a common doc-string.
Before I do that, could you please explain how IntervalIndex.get_loc
gets its doc-string? From the code it seems it shouldn't have one, but it does....
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.
hmm, I think its inheriting it from Index.get_loc, instead this should use the appender method (guess it was omitted somehow).
Mater: ```python In [1]: import pandas as pd; import numpy as np In [2]: arr = ['s%04d' % i for i in np.random.randint(0, 500000 // 10, size=500000)]; s = pd.Series(arr).astype('category') In [3]: %timeit s.cat.set_categories(s.cat.categories) 68.5 ms ± 846 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) ``` HEAD: ```python In [1]: import pandas as pd; import numpy as np In [2]: arr = ['s%04d' % i for i in np.random.randint(0, 500000 // 10, size=500000)] s = pd.Series(arr).astype('category') In [3]: %timeit s.cat.set_categories(s.cat.categories) 7.43 ms ± 110 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) ``` Closes pandas-dev#17508
Ensures index is set when requested during reading of a Stata dta file Deprecates and renames index to index_col for API consistence closes pandas-dev#16342
Hi @jreback. I've updated the examples for other index classes as well, but I've messed up the commits, lots of other people's commit are included also. Should I just delete this branch and make a new pull request? |
@topper-123 generally just push (or force push) to the same branch is easiest, but since you did it ok |
This pull request adds some examples to
Index.get_loc
(actually toIndex._index_shared_docs['get_loc']
) and clarifies the return value.