Skip to content

Commit 6b28ead

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

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-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
@@ -12,6 +12,7 @@
1212
Timestamp,
1313
)
1414
from pandas._libs.tslibs import to_offset
15+
from pandas.compat.numpy import np_version_gt2
1516

1617
from pandas.core.dtypes.dtypes import PeriodDtype
1718

@@ -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

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import numpy as np
1111

12+
from pandas.compat.numpy import np_version_gt2
13+
1214
from pandas.core.dtypes.base import ExtensionDtype
1315

1416
import pandas as pd
@@ -49,6 +51,8 @@ def __init__(self, values, attr=None) -> None:
4951

5052
@classmethod
5153
def _from_sequence(cls, scalars, *, dtype=None, copy=False):
54+
if np_version_gt2 and not copy:
55+
copy = None
5256
data = np.array(scalars, dtype="float64", copy=copy)
5357
return cls(data)
5458

0 commit comments

Comments
 (0)