-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: astype to pyarrow does not copy np array #50984
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
worth adding this to tm.shares_memory? |
Raises a NotImplementedError (no arrow support) Will have a look at this in a follow up |
pandas/core/arrays/arrow/array.py
Outdated
@@ -218,6 +218,9 @@ def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy: bool = Fal | |||
if isinstance(scalars, cls): | |||
scalars = scalars._data | |||
elif not isinstance(scalars, (pa.Array, pa.ChunkedArray)): | |||
if copy and is_array_like(scalars): | |||
# pa array should not get updated when numpy array is updated | |||
scalars = scalars.copy() |
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.
Is it worth specifying np.array(scalars, copy=True)
manually? There might be an off chance the arraylike doesn't have a copy
method?
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 would cast our nullables to object, so not ideal
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 gotcha. Would calling copy.copy(...)
be safer 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.
We need deepcopy, but this should do the trick
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 might be an off chance the arraylike doesn't have a copy method?
might make more sense to raise than guess if this occurs?
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.
No preference here, cc @mroeschke
Thanks @phofl |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.cc @mroeschke
This should copy. You can't update the pyarrow array, but the parent array can get updated which propagates to the pyarrow array.