Skip to content

Commit 3ae782d

Browse files
committed
MAINT: Adjust the codebase to the new np.array copy keyword meaning
1 parent e14a9bd commit 3ae782d

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
@@ -1919,7 +1919,7 @@ def to_numpy(
19191919
dtype = np.dtype(dtype)
19201920
result = self._mgr.as_array(dtype=dtype, copy=copy, na_value=na_value)
19211921
if result.dtype is not dtype:
1922-
result = np.array(result, dtype=dtype, copy=False)
1922+
result = np.asarray(result, dtype=dtype)
19231923

19241924
return result
19251925

pandas/tests/arrays/test_datetimelike.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
TimedeltaIndex,
2424
)
2525
import pandas._testing as tm
26+
from pandas.compat.numpy import np_version_gt2
2627
from pandas.core.arrays import (
2728
DatetimeArray,
2829
NumpyExtensionArray,
@@ -952,13 +953,14 @@ def test_int_properties(self, timedelta_index, propname):
952953

953954
def test_array_interface(self, timedelta_index):
954955
arr = timedelta_index._data
956+
copy_false = None if np_version_gt2 else False
955957

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

@@ -967,7 +969,7 @@ def test_array_interface(self, timedelta_index):
967969
expected = arr._ndarray
968970
assert result is expected
969971
tm.assert_numpy_array_equal(result, expected)
970-
result = np.array(arr, dtype="timedelta64[ns]", copy=False)
972+
result = np.array(arr, dtype="timedelta64[ns]", copy=copy_false)
971973
assert result is expected
972974
tm.assert_numpy_array_equal(result, expected)
973975
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)