Skip to content

Commit 6edd0e0

Browse files
committed
MAINT: Adjust the codebase to the new np.array copy keyword meaning
1 parent db11e25 commit 6edd0e0

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,7 @@ def to_numpy(
19781978
dtype = np.dtype(dtype)
19791979
result = self._mgr.as_array(dtype=dtype, copy=copy, na_value=na_value)
19801980
if result.dtype is not dtype:
1981-
result = np.array(result, dtype=dtype, copy=False)
1981+
result = np.asarray(result, dtype=dtype)
19821982

19831983
return result
19841984

pandas/tests/arrays/test_datetimelike.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
TimedeltaIndex,
2222
)
2323
import pandas._testing as tm
24+
from pandas.compat.numpy import np_version_gt2
2425
from pandas.core.arrays import (
2526
DatetimeArray,
2627
NumpyExtensionArray,
@@ -950,13 +951,14 @@ def test_int_properties(self, timedelta_index, propname):
950951

951952
def test_array_interface(self, timedelta_index):
952953
arr = timedelta_index._data
954+
copy_false = None if np_version_gt2 else False
953955

954956
# default asarray gives the same underlying data
955957
result = np.asarray(arr)
956958
expected = arr._ndarray
957959
assert result is expected
958960
tm.assert_numpy_array_equal(result, expected)
959-
result = np.array(arr, copy=False)
961+
result = np.array(arr, copy=copy_false)
960962
assert result is expected
961963
tm.assert_numpy_array_equal(result, expected)
962964

@@ -965,7 +967,7 @@ def test_array_interface(self, timedelta_index):
965967
expected = arr._ndarray
966968
assert result is expected
967969
tm.assert_numpy_array_equal(result, expected)
968-
result = np.array(arr, dtype="timedelta64[ns]", copy=False)
970+
result = np.array(arr, dtype="timedelta64[ns]", copy=copy_false)
969971
assert result is expected
970972
tm.assert_numpy_array_equal(result, expected)
971973
result = np.array(arr, dtype="timedelta64[ns]")

pandas/tests/extension/array_with_attr/array.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pandas.core.dtypes.base import ExtensionDtype
1313

1414
import pandas as pd
15+
from pandas.compat.numpy import np_version_gt2
1516
from pandas.core.arrays import ExtensionArray
1617

1718
if TYPE_CHECKING:
@@ -49,6 +50,8 @@ def __init__(self, values, attr=None) -> None:
4950

5051
@classmethod
5152
def _from_sequence(cls, scalars, *, dtype=None, copy=False):
53+
if np_version_gt2 and not copy:
54+
copy = None
5255
data = np.array(scalars, dtype="float64", copy=copy)
5356
return cls(data)
5457

0 commit comments

Comments
 (0)