Skip to content

Commit 5e4cb87

Browse files
add similar test to base extension tests
1 parent 4217baf commit 5e4cb87

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/extension/base/interface.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import numpy as np
22
import pytest
33

4+
from pandas.compat.numpy import np_version_gt2
5+
46
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
57
from pandas.core.dtypes.common import is_extension_array_dtype
68
from pandas.core.dtypes.dtypes import ExtensionDtype
@@ -71,6 +73,25 @@ def test_array_interface(self, data):
7173
expected = construct_1d_object_array_from_listlike(list(data))
7274
tm.assert_numpy_array_equal(result, expected)
7375

76+
def test_array_interface_copy(self, data):
77+
result_copy1 = np.array(data, copy=True)
78+
result_copy2 = np.array(data, copy=True)
79+
assert not np.may_share_memory(result_copy1, result_copy2)
80+
81+
if not np_version_gt2:
82+
# copy=False semantics are only supported in NumPy>=2.
83+
return
84+
85+
try:
86+
result_nocopy1 = np.array(data, copy=False)
87+
except ValueError:
88+
# An error is always acceptable for `copy=False`
89+
return
90+
91+
result_nocopy2 = np.array(data, copy=False)
92+
# If copy=False was given and did not raise, these must share the same data
93+
assert np.may_share_memory(result_nocopy1, result_nocopy2)
94+
7495
def test_is_extension_array_dtype(self, data):
7596
assert is_extension_array_dtype(data)
7697
assert is_extension_array_dtype(data.dtype)

0 commit comments

Comments
 (0)