-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Add lazy copy for sort_values #50643
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
Conversation
Co-authored-by: Matthew Roeschke <[email protected]>
view = obj[:] | ||
obj.sort_values(inplace=True, **kwargs) | ||
|
||
assert np.shares_memory(obj.values, view.values) |
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.
Actually, this is failing with ArrayManager (failing CI)
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.
.values
on a DataFrame is always a copy for ArrayManager, so the generic obj.values
doesn't work here:
assert np.shares_memory(obj.values, view.values) | |
if isinstance(obj, DataFrame): | |
assert np.shares_memory(get_array(obj, "a"), get_array(view, "a")) | |
else: | |
assert np.shares_memory(obj.values, view.values) |
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.
You will have to use the same pattern below, so can probably simplify this if we give the Series a name so can use get_array
in all cases.
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.
While testing this, I just pushed the changes I was doing locally, hopefully you weren't yet working on it.
using_copy_on_write | ||
or using_array_manager | ||
and isinstance(obj, DataFrame) | ||
and pd.options.mode.copy_on_write |
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.
ArrayManager never uses Copy-on-Write (we should maybe error when setting those two options at the same time), so this check (and the or using_array_manager
two lines above) shouldn't be needed. I suppose the reason it seemingly did give a copy is because of the .values
giving a copy
Thx for fixing this, merged main to ensure that the dev builds get through |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.