Skip to content

DOC: Improve code example for Index.get_indexer #21511

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 2 commits into from
Jun 19, 2018

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Jun 16, 2018

Make code example clearer for Index.get_indexer

@pep8speaks
Copy link

pep8speaks commented Jun 16, 2018

Hello @topper-123! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on June 19, 2018 at 08:19 Hours UTC

@topper-123 topper-123 force-pushed the get_indexer_examples branch 3 times, most recently from e0c60b2 to 59d66ea Compare June 16, 2018 18:47
@codecov
Copy link

codecov bot commented Jun 16, 2018

Codecov Report

Merging #21511 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #21511   +/-   ##
=======================================
  Coverage   91.92%   91.92%           
=======================================
  Files         153      153           
  Lines       49587    49587           
=======================================
  Hits        45583    45583           
  Misses       4004     4004
Flag Coverage Δ
#multiple 90.32% <ø> (ø) ⬆️
#single 41.89% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/base.py 96.62% <ø> (ø) ⬆️

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 9e982e1...64b87e7. Read the comment docs.

@gfyoung gfyoung added Docs Indexing Related to indexing on series/frames, not to indexes themselves labels Jun 17, 2018
Copy link
Member

@gfyoung gfyoung left a comment

Choose a reason for hiding this comment

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

Nice!

cc @jreback

@@ -3148,8 +3148,12 @@ def droplevel(self, level=0):

Examples
--------
>>> indexer = index.get_indexer(new_index)
>>> new_values = cur_values.take(indexer)
>>> index = %(target_klass)s(['c', 'a', 'b'])
Copy link
Member

@jschendel jschendel Jun 17, 2018

Choose a reason for hiding this comment

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

There are docs being generated for both MultiIndex.get_indexer and IntervalIndex.get_indexer that are using this template:

@Appender(_index_shared_docs['get_indexer'] % _index_doc_kwargs)
def get_indexer(self, target, method=None, limit=None, tolerance=None):

@Appender(_index_shared_docs['get_indexer'] % _index_doc_kwargs)
def get_indexer(self, target, method=None, limit=None, tolerance=None):

Other indexes, like PeriodIndex, don't appear to currently have docs generated for this, but inherit the method and would produce a docstring viewable with a command like PeriodIndex.get_indexer? in IPython.

In any of these cases, the %(target_klass)s (I think this should actually be %(klass)s?) would get filled in with one of the aforementioned index types, which would produce an invalid example.

I think it's reasonable to just hardcode this in as Index(['c', 'a', 'b']) and have the user infer the behavior for the specific type of index they're using?

Copy link
Member

@jorisvandenbossche jorisvandenbossche Jun 18, 2018

Choose a reason for hiding this comment

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

I think it's reasonable to just hardcode this in as Index(['c', 'a', 'b']) and have the user infer the behavior for the specific type of index they're using?

+ 1

@topper-123 topper-123 force-pushed the get_indexer_examples branch from 59d66ea to e2e6f39 Compare June 18, 2018 17:22
Copy link
Member

@jschendel jschendel left a comment

Choose a reason for hiding this comment

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

Thanks!

@jorisvandenbossche jorisvandenbossche merged commit 6d34657 into pandas-dev:master Jun 19, 2018
@jorisvandenbossche jorisvandenbossche added this to the 0.24.0 milestone Jun 19, 2018
@jorisvandenbossche
Copy link
Member

@topper-123 Thanks!

@topper-123 topper-123 deleted the get_indexer_examples branch June 19, 2018 08:39
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants