-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
DEPR: deprecate / warn about raising an error in __array__ when copy=False cannot be honore #60340
Comments
take |
1 similar comment
take |
@jorisvandenbossche - I'm having a hard time trying to replicate |
Try this example with latest main:
You need to use a dtype that cannot be converted zero-copy to numpy, such as category I used above (if you would use integers, for example, that will not error). And also you need latest |
Can't seem to replicate on my end, on both import numpy as np
import pandas as pd
print(f"NumPy version: {np.__version__}")
print(f"Pandas version: {pd.__version__}")
ser = pd.Series(["a", "b"], dtype="category")
x = np.array(ser, copy=False)
print(x) Output:
I'm running on macOS 15.1.1 |
Ah, you need numpy > 2.0 |
The numpy 2.0 changed the behavior of the
copy
keyword in__array__
, and especially makingcopy=False
to be strict (raising an error when a zero-copy numpy array is not possible).We only adjusted pandas to update the
copy
handling now in #60046 (issue #57739).But that also introduced a breaking change for anyone doing
np.array(ser, copy=False)
(and who hasn't updated that when updating to numpy 2.0), which historically has always worked fine and could silently give a copy anyway.The idea would be to still include a FutureWarning about this first before raising the error (as now in main) in pandas 3.0.
See #60046 (comment) for more context
The text was updated successfully, but these errors were encountered: