Skip to content

CLN: assorted indexing-related cleanups #31797

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 5 commits into from
Feb 10, 2020

Conversation

jbrockmendel
Copy link
Member

  • _setitem_with_indexer isnt consistent about whether or not it returns anything, make it always-None
  • avoid using private loc method from DataFrame

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

generally looks good one question

@@ -862,7 +862,9 @@ def __getitem__(self, key):

return result
except InvalidIndexError:
pass
if not isinstance(self.index, MultiIndex):
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

Copy link
Member Author

Choose a reason for hiding this comment

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

it wasn't obvious to me that non-MI shouldn't be allowed through here, this should clarify it for future readers (or me once I forget)

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha; does that fix an issue somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, just clarity, avoids doing some other checks before raising

@WillAyd WillAyd added Clean Indexing Related to indexing on series/frames, not to indexes themselves labels Feb 8, 2020
# NB: we can't just use self.loc[key] = value because that
# operates on labels and we need to operate positional for
# backwards-compat, xref GH#31469
self._check_setitem_copy()
self.loc._setitem_with_indexer(key, value)
self.iloc[key] = value
Copy link
Member

Choose a reason for hiding this comment

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

iloc ends up calling the same method, so calling it here directly probably avoids a bunch of duplicate validation.

So I would either leave it as is, or at least check the impact of that, or eg change to iloc._setitem_with_indexer(..) to make it more obvious that it is positional indexing

Copy link
Member Author

Choose a reason for hiding this comment

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

WIll do that for now and revisit in a non-"cleanup" PR

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

# Validate start & stop
if start is not None:
self.get_loc(start)
if stop is not None:
self.get_loc(stop)
is_positional = False
except KeyError:
if self.inferred_type in ["mixed-integer-float", "integer-na"]:
Copy link
Member

Choose a reason for hiding this comment

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

this was not needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

not reachable; the check for self.is_mixed() a few lines up means these inferred_types are impossible

@jreback jreback added this to the 1.1 milestone Feb 9, 2020
@jreback
Copy link
Contributor

jreback commented Feb 9, 2020

does this change anything user facing? (no?)

@jbrockmendel
Copy link
Member Author

does this change anything user facing? (no?)

Correct, nothing user-facing.

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.

@jorisvandenbossche jorisvandenbossche merged commit 6bc2dca into pandas-dev:master Feb 10, 2020
@jorisvandenbossche
Copy link
Member

Thanks!

@jbrockmendel jbrockmendel deleted the indexing-small branch February 10, 2020 16:20
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.

4 participants