Handle CoW in BlockManager.apply #50948
Closed
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.
@phofl seeing that we need the Block methods be aware of CoW (does it make a copy or not? do we need to keep track of a ref or not?) in several cases, I was thinking of this alternative of how to handle this generally. I don't know if it will turn out to be cleaner if has to handle all different cases, but for now I tested it with astype and infer_objects (#50802, #50428).
The idea is that the Block method just tells the manager whether the block that is returned is a view or a copy, and then all the weakref management is centralized in the
BlockManager.apply()
method.It avoids the "hack" of attaching the
_ref
to the block. Now I am writing this, of course also the in case of using the_ref
method, the extracting of those refs could be centralized inapply()
instead of done in bothastype
andconvert
, as it is the case right now in the linked PRs.I think I find the logic a bit simpler here in this PR, especially for
convert
with its block-splitting logic, but it's also not a big difference (and I am of course biased since I wrote this one, and the logic in your PRs I only read ;))Note, I just copied some minimal pieces from your PRs to test this, and didn't bother with typing and cleaning it up etc. If we think this might be a suitable path forward, I would also remove those parts here again, and only add the general infrastructure here, and keep astype/convert for its separate PRs.