-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Make shallow copy for align nocopy with CoW #50917
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
Changes from all commits
a1a6a9d
ed25bed
7f17f19
2aacc42
d06ccdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5429,6 +5429,8 @@ def _reindex_with_indexers( | |
|
||
if (copy or copy is None) and new_data is self._mgr: | ||
new_data = new_data.copy(deep=copy) | ||
elif using_copy_on_write() and new_data is self._mgr: | ||
new_data = new_data.copy(deep=copy) | ||
|
||
return self._constructor(new_data).__finalize__(self) | ||
|
||
|
@@ -9469,6 +9471,7 @@ def _align_series( | |
limit=None, | ||
fill_axis: Axis = 0, | ||
): | ||
uses_cow = using_copy_on_write() | ||
|
||
is_series = isinstance(self, ABCSeries) | ||
|
||
|
@@ -9492,7 +9495,10 @@ def _align_series( | |
if is_series: | ||
left = self._reindex_indexer(join_index, lidx, copy) | ||
elif lidx is None or join_index is None: | ||
left = self.copy(deep=copy) if copy or copy is None else self | ||
if uses_cow: | ||
left = self.copy(deep=copy) | ||
else: | ||
left = self.copy(deep=copy) if copy or copy is None else self | ||
Comment on lines
+9498
to
+9501
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should consider just doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I agree, but would prefer to keep things separate. We have a couple of other methods where we return self in case of len(index)==0 for example, would like to change them all together if we want to. Can put up a pr for this first before merging here if you prefer |
||
else: | ||
left = self._constructor( | ||
self._mgr.reindex_indexer(join_index, lidx, axis=1, copy=copy) | ||
|
@@ -9521,7 +9527,10 @@ def _align_series( | |
left = self._constructor(fdata) | ||
|
||
if ridx is None: | ||
right = other.copy(deep=copy) if copy or copy is None else other | ||
if uses_cow: | ||
right = other.copy(deep=copy) | ||
else: | ||
right = other.copy(deep=copy) if copy or copy is None else other | ||
else: | ||
right = other.reindex(join_index, level=level) | ||
|
||
|
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.
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.
Could you also add an explicit test that covers this?
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 prefer my version, this is easier to read imo. The conditions are nicely aligned.
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.
The align copy false test covers this
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.
Sorry, that wasn't clear ;) This change is in
_reindex_with_indexers
, which is used by align, but is also used throughreindex
? (I assumed that align would use it through reindex, but that's actually not the case I see now, it is using it directly) And so I was wondering if this change is also needed for correct behaviour ofreindex
(and so if we missed something there), and if so, it would be good to also have a test forreindex
that covers this.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 got you.
We can't get there through reindex, because we have early exits preventing us from reaching
_reindex_with_indexers
if both axes are equal to the object that is reindexed.I also looked into avoiding this function call when using align, but there is nothing to be gained there. It makes more sense covering this here.