File tree Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Original file line number Diff line number Diff line change
1
+ import warnings
2
+
1
3
import numpy as np
2
4
import pytest
3
5
@@ -82,13 +84,27 @@ def test_array_interface_copy(self, data):
82
84
# copy=False semantics are only supported in NumPy>=2.
83
85
return
84
86
87
+ warning_raised = False
85
88
msg = "Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed"
86
- with tm .assert_produces_warning (FutureWarning , match = msg ):
89
+ with warnings .catch_warnings (record = True ) as w :
90
+ warnings .simplefilter ("always" )
87
91
result_nocopy1 = np .array (data , copy = False )
88
-
89
- result_nocopy2 = np .array (data , copy = False )
90
- # If copy=False was given and did not raise, these must share the same data
91
- assert np .may_share_memory (result_nocopy1 , result_nocopy2 )
92
+ assert len (w ) <= 1
93
+ if len (w ):
94
+ warning_raised = True
95
+ assert msg in str (w [0 ].message )
96
+
97
+ with warnings .catch_warnings (record = True ) as w :
98
+ warnings .simplefilter ("always" )
99
+ result_nocopy2 = np .array (data , copy = False )
100
+ assert len (w ) <= 1
101
+ if len (w ):
102
+ warning_raised = True
103
+ assert msg in str (w [0 ].message )
104
+
105
+ if not warning_raised :
106
+ # If copy=False was given and did not raise, these must share the same data
107
+ assert np .may_share_memory (result_nocopy1 , result_nocopy2 )
92
108
93
109
def test_is_extension_array_dtype (self , data ):
94
110
assert is_extension_array_dtype (data )
Original file line number Diff line number Diff line change 6
6
import numpy as np
7
7
import pytest
8
8
9
+ from pandas .compat .numpy import np_version_gt2
10
+
9
11
import pandas as pd
10
12
import pandas ._testing as tm
11
13
from pandas .tests .extension import base
@@ -289,6 +291,24 @@ def test_series_repr(self, data):
289
291
def test_unary_ufunc_dunder_equivalence (self , data , ufunc ):
290
292
super ().test_unary_ufunc_dunder_equivalence (data , ufunc )
291
293
294
+ def test_array_interface_copy (self , data ):
295
+ result_copy1 = np .array (data , copy = True )
296
+ result_copy2 = np .array (data , copy = True )
297
+ assert not np .may_share_memory (result_copy1 , result_copy2 )
298
+ if not np_version_gt2 :
299
+ # copy=False semantics are only supported in NumPy>=2.
300
+ return
301
+
302
+ try :
303
+ result_nocopy1 = np .array (data , copy = False )
304
+ except ValueError :
305
+ # An error is always acceptable for `copy=False`
306
+ return
307
+
308
+ result_nocopy2 = np .array (data , copy = False )
309
+ # If copy=False was given and did not raise, these must share the same data
310
+ assert np .may_share_memory (result_nocopy1 , result_nocopy2 )
311
+
292
312
293
313
def test_take_na_value_other_decimal ():
294
314
arr = DecimalArray ([decimal .Decimal ("1.0" ), decimal .Decimal ("2.0" )])
You can’t perform that action at this time.
0 commit comments