File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -2014,6 +2014,12 @@ def empty(self) -> bool:
2014
2014
def __array__ (
2015
2015
self , dtype : npt .DTypeLike | None = None , copy : bool | None = None
2016
2016
) -> np .ndarray :
2017
+ if copy is False and not self ._mgr .is_single_block and not self .empty :
2018
+ # check this manually, otherwise ._values will already return a copy
2019
+ # and np.array(values, copy=False) will not raise an error
2020
+ raise ValueError (
2021
+ "Unable to avoid copy while creating an array as requested."
2022
+ )
2017
2023
values = self ._values
2018
2024
if copy is None :
2019
2025
# Note: branch avoids `copy=None` for NumPy 1.x support
Original file line number Diff line number Diff line change @@ -138,6 +138,9 @@ def test_dataframe_multiple_numpy_dtypes():
138
138
assert not np .shares_memory (arr , get_array (df , "a" ))
139
139
assert arr .flags .writeable is True
140
140
141
+ with pytest .raises (ValueError , match = "Unable to avoid copy while creating" ):
142
+ arr = np .array (df , copy = False )
143
+
141
144
142
145
def test_values_is_ea ():
143
146
df = DataFrame ({"a" : date_range ("2012-01-01" , periods = 3 )})
You can’t perform that action at this time.
0 commit comments