-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
REF: avoid mutating Series._values directly in setitem but defer to Manager method #41879
REF: avoid mutating Series._values directly in setitem but defer to Manager method #41879
Conversation
I lean towards using a new method instead of overloading |
@jreback to be clear, it's the existing manager
I can certainly add a new method (eg |
The last commits adds the version with a separate method instead of keyword. Either way is fine for me (it's also easy to revert) |
BTW im picky on the implementation, but in general i think this is a very good idea |
Any further response here? |
i will look at some point |
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this. |
This is not stale, but waiting on further comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable to me. can you rebase and small comments.
@@ -1287,8 +1287,24 @@ def apply(self, func, **kwargs): | |||
return type(self)([new_array], self._axes) | |||
|
|||
def setitem(self, indexer, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you type annotate the return values at the very least on these (Any is fine) just indicative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an existing method, all other Manager methods with general indexer
argument are not yet typed, so I would prefer to leave that for a typing-specific PR (I also thought that we generally want to avoid adding Any
for "not yet typed" unless it's really "any").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comment, otherwise lgtm.
@@ -1287,8 +1287,24 @@ def apply(self, func, **kwargs): | |||
return type(self)([new_array], self._axes) | |||
|
|||
def setitem(self, indexer, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kk
pandas/core/internals/base.py
Outdated
@@ -159,6 +159,18 @@ def array(self): | |||
""" | |||
return self.arrays[0] # type: ignore[attr-defined] | |||
|
|||
def setitem_inplace(self, indexer, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you type the output here (e.g. -> None)
i think the failures are related here, e.g. the stacklevel is changed. so prob need to use |
actually these are likley #42857 but this PR may affect as well (so let's fix that one first) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…es-setitem-inplace
There are currently two cases where the Series code directly modifies the underlying values itself (
self._values[..] = ..
), while most setitem code paths end up going through a specific indexing method that all end up in the Manager doing the actual modification of the values.Apart from being a bit inconsistent (it's good to have all eventual modifications consistently happening inside the manager, I think), I also need to move this to the manager for being able to check for copy-on-write in #41878.
Since I think this is a generally useful change, moving it out of the CoW PR.