Skip to content

Commit ac0573c

Browse files
committed
raise warning on JSON __array__
1 parent f0bec10 commit ac0573c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pandas/tests/extension/json/array.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
TYPE_CHECKING,
2626
Any,
2727
)
28+
import warnings
2829

2930
import numpy as np
3031

32+
from pandas.util._exceptions import find_stack_level
33+
3134
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
3235
from pandas.core.dtypes.common import (
3336
is_bool_dtype,
@@ -148,8 +151,14 @@ def __ne__(self, other):
148151

149152
def __array__(self, dtype=None, copy=None):
150153
if copy is False:
151-
raise ValueError(
152-
"Unable to avoid copy while creating an array as requested."
154+
warnings.warn(
155+
"Starting on NumPy 2.0, the behavior of the 'copy' keyword has changed "
156+
"and passing 'copy=False' raises an error when a zero-copy NumPy array "
157+
"is not possible, Pandas will follow this behavior starting with "
158+
"version 3.0. This conversion to NumPy requires a copy, but "
159+
"'copy=False' was passed. Consider using 'np.asarray(..)' instead.",
160+
FutureWarning,
161+
stacklevel=find_stack_level(),
153162
)
154163

155164
if dtype is None:

0 commit comments

Comments
 (0)