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+
13import numpy as np
24import pytest
35
@@ -82,13 +84,27 @@ def test_array_interface_copy(self, data):
8284 # copy=False semantics are only supported in NumPy>=2.
8385 return
8486
87+ warning_raised = False
8588 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" )
8791 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 )
92108
93109 def test_is_extension_array_dtype (self , data ):
94110 assert is_extension_array_dtype (data )
Original file line number Diff line number Diff line change 66import numpy as np
77import pytest
88
9+ from pandas .compat .numpy import np_version_gt2
10+
911import pandas as pd
1012import pandas ._testing as tm
1113from pandas .tests .extension import base
@@ -289,6 +291,24 @@ def test_series_repr(self, data):
289291 def test_unary_ufunc_dunder_equivalence (self , data , ufunc ):
290292 super ().test_unary_ufunc_dunder_equivalence (data , ufunc )
291293
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+
292312
293313def test_take_na_value_other_decimal ():
294314 arr = DecimalArray ([decimal .Decimal ("1.0" ), decimal .Decimal ("2.0" )])
You can’t perform that action at this time.
0 commit comments