Skip to content

REF: separate indexer utilities from indexing.py #27229

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 22 commits into from
Jul 10, 2019

Conversation

jbrockmendel
Copy link
Member

A couple things going on here.

  • Take simple, low-dependency, not-used-in-indexing.py functions out of indexing.py and put them in indexers.py.
    • A couple of runtime-defined functions in internals get moved here too.
    • Avoids some runtime imports (i.e. simplify dependency structure)
    • Fixes some incorrect private names
    • Adds typing
  • Simplify some indexing.py methods
    • Avoid duplicated validation calls
    • Add typing
    • De-duplicate _get_slice_axis method
    • Move code outside of try/except blocks to clarify what the failure modes are.

Medium-term goals in indexing.py

  • Isolate internals access
  • refactor _setitem_with_indexer (over 300 lines)

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

just some quick comments
will have a full look later

+1 on refactoring things

return is_list_like(key) and not (isinstance(key, tuple) and type(key) is not tuple)


def is_scalar_indexer(indexer, arr_value) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

if possible to type pls do so (may be tricky)

I would type with Any explicity if it’s truly that
so we know this is done (meaning it has been typed)

possible to use reveal_type to figure things out here

Copy link
Member Author

Choose a reason for hiding this comment

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

ATM I've added types for everything I had figured out with sufficient certainty. I'd rather leave it clearly-unfinished so it gets more attention than put Any if we can be more specific

Copy link
Contributor

Choose a reason for hiding this comment

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

can you fix this doc-sring in followup and type as much as possible here

@jreback jreback added Clean Indexing Related to indexing on series/frames, not to indexes themselves Internals Related to non-user accessible pandas implementation labels Jul 4, 2019
@jreback
Copy link
Contributor

jreback commented Jul 4, 2019

note as a post or pre-cursor to this I would form pandas/core/indexing/ and move indexing.py (and indexers.py) there as well

@jbrockmendel
Copy link
Member Author

note as a post or pre-cursor to this I would form pandas/core/indexing/ and move indexing.py (and indexers.py) there as well

Sure. Obvious preference for post-cursor.

@pep8speaks
Copy link

pep8speaks commented Jul 6, 2019

Hello @jbrockmendel! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-07-08 13:51:16 UTC

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

just a couple of doc-strings I think (in the first section), then can merge this

else:
return self.obj._take(indexer, axis=axis)
indexer = self._convert_slice_indexer(slice_obj, axis)
assert isinstance(indexer, slice), type(indexer)
Copy link
Contributor

Choose a reason for hiding this comment

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

prob better off to have this assert in _slice

@jbrockmendel
Copy link
Member Author

Added one more docstring, left un-docstringed is_scalar_indexer and is_empty_indexer because I'm not totally clear on what those functions are doing (possibly an extra indentation in is_scalar_indexer? it is almost identical to the last 5 lines of is_empty_indexer)

Added a note about InvalidIndexError being for geopandas.

# Indexer Validation


def check_setitem_lengths(indexer, value, values) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

type

@jreback jreback added this to the 0.25.0 milestone Jul 10, 2019
@jreback jreback merged commit 298c7cc into pandas-dev:master Jul 10, 2019
@jreback
Copy link
Contributor

jreback commented Jul 10, 2019

thanks. in followups we need to move / consolidate these things; also a typing pass would be helpful.

@jbrockmendel jbrockmendel deleted the clnindexing branch July 10, 2019 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Indexing Related to indexing on series/frames, not to indexes themselves Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants