-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CoW: Avoid warning in apply for mixed dtype frame #56212
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
+45
−15
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3303b7d
CoW: Avoid warning in apply for mixed dtype frame
phofl 2e579ba
CoW: Avoid warning in apply for mixed dtype frame
phofl 9560245
CoW: Avoid warning in apply for mixed dtype frame
phofl 82bf5cb
Update
phofl eab6b06
Merge branch 'main' into apply_cow_warning
phofl 5b8d008
Fixup
phofl c2a9183
Merge remote-tracking branch 'upstream/main' into apply_cow_warning
jorisvandenbossche 5065b78
add more comments + rename test
jorisvandenbossche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To be honest, I don't understand how this part adds an extra ref after the first row (i.e. the reason you need to reset
refs
to have one ref to only itself)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.
Ah, I assume that's because we create a shallow copy of the result:
pandas/pandas/core/apply.py
Lines 1078 to 1084 in 7b528c9
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.
Yep exactly
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.
Would it be cleaner to create a shallow "copy" of the Series that does not keep a reference? (I don't think we have any helper function to do that right now? except for
Series(results[i]._values, copy=False, index=.., name=..)
, like what you did in theeval
PR to create Series objects without a reference)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.
My assumption was that this is optimized for performance and I didn’t want to screw with that. And keeping the ugly parts in one method seemed like a fine compromise
that said, the udf could also set up references that could screw us over
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.
It's already taking a shallow copy always (even when not needed), so having a specialized shallow copy without tracking refs should at best slightly improve things.
The logic about requiring this shallow copy also already lives where the series_generator is used, so I think I find it slightly clearer to consolidate that logic there
Now, actually implementing a
Series._shallow_copy_without_refs()
is not fully trivial because AFAIK we can't just reuse the existing mgr and blockcopy
methods and reset the refs after the fact, as that then already appended the refs object which is shared with the series generator series with a new ref.So let's consider that for a follow-up PR if I want to pursue that ;)
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.
I am just going to update some comments here, then
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.
Yeah I'd rather not do too many helpers that make this easy since you really shouldn't be doing this