-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
DEPR: Raise FutureWarning
about raising an error in __array__ when copy=False cannot be honored
#60395
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: Raise FutureWarning
about raising an error in __array__ when copy=False cannot be honored
#60395
Changes from 1 commit
2eb106c
f0bec10
ac0573c
504a484
11ae896
8574f97
fab1f17
1c5d103
f419a91
ce83e09
1820f78
d466e24
9786ee3
f9fc8e8
9731c60
60c5274
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 |
---|---|---|
|
@@ -663,6 +663,16 @@ def __array__( | |
) -> np.ndarray: | ||
"""Correctly construct numpy arrays when passed to `np.asarray()`.""" | ||
if copy is False: | ||
import warnings | ||
|
||
from pandas.util._exceptions import find_stack_level | ||
|
||
warnings.warn( | ||
"Numpy>=2.0 changed copy keyword's behavior, making copy=False" | ||
"raise an error when a zero-copy numpy array is not possible", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
# TODO: By using `zero_copy_only` it may be possible to implement this | ||
raise ValueError( | ||
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. This error should then be removed (we are adding the warning instead of the error, to warn people it will error in the future). 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. Gotcha, I initially thought we would raise both an error and a warning. |
||
"Unable to avoid copy while creating an array as requested." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1672,6 +1672,16 @@ def __array__( | |
array(['a', 'b'], dtype=object) | ||
""" | ||
if copy is False: | ||
import warnings | ||
|
||
from pandas.util._exceptions import find_stack_level | ||
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. Same here about the imports (and similar for next cases) |
||
|
||
warnings.warn( | ||
"Numpy>=2.0 changed copy keyword's behavior, making copy=False " | ||
"raise an error when a zero-copy numpy array is not possible", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
raise ValueError( | ||
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. And same for the errors |
||
"Unable to avoid copy while creating an array as requested." | ||
) | ||
|
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 can move those warnings to the top of the file