Skip to content

REF: de-nest Series getitem/setitem checks #33447

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
wants to merge 1 commit into from

Conversation

jbrockmendel
Copy link
Member

ATM the first checks we do in Series.__getitem__ and __setitem__ are for get_loc with some not-totally-straightforward try/except logic.

This moves the slice case and the com.is_bool_indexer case up, and aligns the ordering of the checks between getitem/setitem.

Getting the com.is_bool_indexer case out from the try/except in setitem is particularly nice.

That said, this may not be what we want to do. This will very slightly improve performance in the cases moved up, and equally slightly harm performance in the scalar case. AFAIK the current ordering is not based on optimizing one case over the others.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

I suppose the isinstance(key, slice) is not costly, but about the is_bool_indexer, I am not so sure. I would at least do some timings to check that (see also the comments that were present)

@@ -897,26 +908,14 @@ def __getitem__(self, key):
else:
raise

if not key_is_scalar:
# avoid expensive checks if we know we have a scalar
Copy link
Member

Choose a reason for hiding this comment

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

This comment might be relevant? Also if you move it up as you did now, you can keep this scalar check?

@jbrockmendel
Copy link
Member Author

but about the is_bool_indexer, I am not so sure

yah, im torn on this. I think following #33404 i can improve the try/except blocks to allow us to retain the current ordering while also getting the de-nesting we get here

@jreback jreback added Clean Indexing Related to indexing on series/frames, not to indexes themselves labels Apr 10, 2020
@jreback
Copy link
Contributor

jreback commented Apr 10, 2020

can you rebase following #33404 merge with any changes you are planning

@jbrockmendel
Copy link
Member Author

mothballing until after the next pass

@jbrockmendel jbrockmendel deleted the ref-earlier branch April 14, 2020 03:17
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants