Skip to content

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

Closed
Closed
Changes from 2 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0f16e2e
Added examples to pd.Index.get_loc
Aug 30, 2017
2c098cd
use target_klass so class name is properly updated for subclasses
Sep 1, 2017
9e425d6
TST: Enable tests in test_tools.py (#17405)
jschendel Sep 1, 2017
f7fe429
TST: remove tests and docs for legacy (pre 0.12) hdf5 support (#17404)
topper-123 Sep 1, 2017
8351f86
Tslib unused (#17402)
jbrockmendel Sep 1, 2017
1981b67
DOC: Cleaned references to pandas <v0.12 in docs (#17375)
topper-123 Sep 2, 2017
c2d0481
Remove unused _day and _month attrs (#17431)
jbrockmendel Sep 4, 2017
5bca6ce
DOC: Clean-up references to v12 to v14 (both included) (#17420)
topper-123 Sep 5, 2017
25d5299
BUG: Plotting Timedelta on y-axis #16953 (#17430)
s-weigand Sep 6, 2017
84a39f9
COMPAT: handle pyarrow deprecation of timestamps_to_ms in .from_panda…
jreback Sep 6, 2017
d457791
DOC/TST: Add examples to MultiIndex.get_level_values + related change…
topper-123 Sep 6, 2017
b869446
Dont re-pin total_seconds as it is already implemented (#17432)
jbrockmendel Sep 7, 2017
3a12687
BUG: Return local Timestamp.weekday_name attribute (#17354) (#17377)
mroeschke Sep 7, 2017
fd137f5
BUG: intersection of decreasing RangeIndexes (#17374)
toobaz Sep 7, 2017
93e23a7
Remove property that re-computed microsecond (#17331)
jbrockmendel Sep 7, 2017
20fee85
cleaned references to pandas v0.15 and v0.16 in docs (#17442)
topper-123 Sep 7, 2017
24b440e
BUG: revert collision warning (#17298)
deniederhut Sep 7, 2017
8a8a4fd
cdef out dtype for _Timestamp._get_field (#17457)
mroeschke Sep 7, 2017
9dc01c4
DOC: Add Timestamp, Period, Timedelta, and Interval to api.rst (#17424)
GuessWhoSamFoo Sep 7, 2017
aee2ae0
DOC: to_json (#17461)
majiang Sep 7, 2017
3a291bb
BUG: Index._searchsorted_monotonic(..., side='right') returns the lef…
jschendel Sep 7, 2017
ee6185e
COMPAT: Pypy tweaks (#17351)
mattip Sep 7, 2017
46832ac
Replace * imports with explicit imports; remove unused declared const…
jbrockmendel Sep 8, 2017
9c4e4c8
Removed Timedelta.is_populated and fixed spelling errors (#17469)
GuessWhoSamFoo Sep 8, 2017
7e4e8ac
PERF: Implement get_freq_code in cython frequencies (#17422)
jbrockmendel Sep 8, 2017
3ccb88c
Fix typo in setup.py introduced by 17422 (#17473)
jbrockmendel Sep 8, 2017
d6df8ea
Follow up to #17422 (#17472)
jbrockmendel Sep 8, 2017
fdbc6b8
MAINT: calcurate --> calculate in _doctools.py
gfyoung Sep 9, 2017
23050dc
BUG: Fix TypeError caused by GH13374 (#17465)
matthax Sep 10, 2017
c3ad501
Remove incorrect kwds from DateOffset tests (#17486)
jbrockmendel Sep 10, 2017
e6aed2e
Remove pyx dependencies from setup (#17478)
jbrockmendel Sep 10, 2017
42ed4f1
ENH: Add Styler.where (#17474)
Licht-T Sep 11, 2017
f3b6d1f
Add file-like object to docs (#17492)
rvernica Sep 11, 2017
46856c3
Implement _is_utc in timezones (#17419)
jbrockmendel Sep 11, 2017
34cc2e8
Follow-up to #17419 (#17497)
jbrockmendel Sep 12, 2017
9a84274
DOC: fix parquet example to not use ns
jreback Sep 12, 2017
d46b027
Prevent UnicodeDecodeError in pivot_table under Py2 (#17489)
mpenkov Sep 12, 2017
e682902
DEPR: Add warning for True for dropna of SeriesGroupBy.nth (#17493)
tnir Sep 12, 2017
83436af
COMPAT: Iteration should always yield a python scalar (#17491)
jreback Sep 12, 2017
633be31
DOC: grammatical mistake (#17511)
Giftlin Sep 13, 2017
f6d4d70
removed versionadded <0.17 (#17504)
topper-123 Sep 13, 2017
f11bbf2
DOC: grammatical mistakes (#17512)
Giftlin Sep 13, 2017
eef810e
COMPAT: followup to #17491 (#17503)
jreback Sep 13, 2017
fa557f7
De-privatize timezone funcs (#17502)
jbrockmendel Sep 13, 2017
2cf2566
Make *_range functions consistent (#17482)
jschendel Sep 14, 2017
97abd2c
TST: Made s3 related tests mock boto (#17388)
kirkhansen Sep 14, 2017
0097cb7
PERF: Avoid values in Categorical.set_categories (#17515)
TomAugspurger Sep 14, 2017
06a6e63
remove period_helper from non-period reqs (#17531)
jbrockmendel Sep 14, 2017
ad70ed4
Fix bug where offset.copy() != offset (#17452)
jbrockmendel Sep 14, 2017
94266d4
PERF: Faster CategoricalIndex from categorical (#17513)
TomAugspurger Sep 14, 2017
9b21c54
Remove unnecessary iNaT checks from _Period properties (#17421)
jbrockmendel Sep 15, 2017
72c3888
CLN: Fix Spelling Errors (#17535)
jschendel Sep 15, 2017
328c7e1
Cut/paste (most) remaining tz funcs to tslibs/timezones (#17526)
jbrockmendel Sep 15, 2017
9ec157b
DOC: Spelling + grammar in chainmap_impl.py (#17548)
Giftlin Sep 16, 2017
f5cfdbb
BUG: Set index when reading Stata file (#17328)
bashtage Sep 16, 2017
0674c42
Added examples to pd.Index.get_loc
Aug 30, 2017
71dfe09
use klass + add examples for CategoricalIndex, IntervalIndex and
Sep 1, 2017
12ce8d5
merge conflict
Sep 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2450,10 +2450,24 @@ def _get_unique_index(self, dropna=False):

Returns
-------
loc : int if unique index, possibly slice or mask if not
loc : int if unique index, slice if monotonic index, else mask

Examples
---------
>>> unique_index = pd.%(target_klass)s(list('abc'))
Copy link
Contributor

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.

Copy link
Contributor Author

@topper-123 topper-123 Sep 6, 2017

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

Copy link
Contributor

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

>>> unique_index.get_loc('b')
1

>>> monotonic_index = pd.%(target_klass)s(list('abbc'))
>>> monotonic_index.get_loc('b')
slice(1, 3, None)

>>> non_monotonic_index = pd.%(target_klass)s(list('abcb'))
>>> non_monotonic_index.get_loc('b')
array([False, True, False, True], dtype=bool)
"""

@Appender(_index_shared_docs['get_loc'])
@Appender(_index_shared_docs['get_loc'] % _index_doc_kwargs)
def get_loc(self, key, method=None, tolerance=None):
if method is None:
if tolerance is not None:
Expand Down