12
12
Timestamp ,
13
13
)
14
14
from pandas ._libs .tslibs import to_offset
15
+ from pandas .compat .numpy import np_version_gt2
15
16
16
17
from pandas .core .dtypes .dtypes import PeriodDtype
17
18
@@ -640,13 +641,14 @@ def test_round(self, arr1d):
640
641
641
642
def test_array_interface (self , datetime_index ):
642
643
arr = datetime_index ._data
644
+ copy_false = None if np_version_gt2 else False
643
645
644
646
# default asarray gives the same underlying data (for tz naive)
645
647
result = np .asarray (arr )
646
648
expected = arr ._ndarray
647
649
assert result is expected
648
650
tm .assert_numpy_array_equal (result , expected )
649
- result = np .array (arr , copy = False )
651
+ result = np .array (arr , copy = copy_false )
650
652
assert result is expected
651
653
tm .assert_numpy_array_equal (result , expected )
652
654
@@ -655,7 +657,7 @@ def test_array_interface(self, datetime_index):
655
657
expected = arr ._ndarray
656
658
assert result is expected
657
659
tm .assert_numpy_array_equal (result , expected )
658
- result = np .array (arr , dtype = "datetime64[ns]" , copy = False )
660
+ result = np .array (arr , dtype = "datetime64[ns]" , copy = copy_false )
659
661
assert result is expected
660
662
tm .assert_numpy_array_equal (result , expected )
661
663
result = np .array (arr , dtype = "datetime64[ns]" )
@@ -698,6 +700,7 @@ def test_array_tz(self, arr1d):
698
700
# GH#23524
699
701
arr = arr1d
700
702
dti = self .index_cls (arr1d )
703
+ copy_false = None if np_version_gt2 else False
701
704
702
705
expected = dti .asi8 .view ("M8[ns]" )
703
706
result = np .array (arr , dtype = "M8[ns]" )
@@ -706,17 +709,18 @@ def test_array_tz(self, arr1d):
706
709
result = np .array (arr , dtype = "datetime64[ns]" )
707
710
tm .assert_numpy_array_equal (result , expected )
708
711
709
- # check that we are not making copies when setting copy=False
710
- result = np .array (arr , dtype = "M8[ns]" , copy = False )
712
+ # check that we are not making copies when setting copy=copy_false
713
+ result = np .array (arr , dtype = "M8[ns]" , copy = copy_false )
711
714
assert result .base is expected .base
712
715
assert result .base is not None
713
- result = np .array (arr , dtype = "datetime64[ns]" , copy = False )
716
+ result = np .array (arr , dtype = "datetime64[ns]" , copy = copy_false )
714
717
assert result .base is expected .base
715
718
assert result .base is not None
716
719
717
720
def test_array_i8_dtype (self , arr1d ):
718
721
arr = arr1d
719
722
dti = self .index_cls (arr1d )
723
+ copy_false = None if np_version_gt2 else False
720
724
721
725
expected = dti .asi8
722
726
result = np .array (arr , dtype = "i8" )
@@ -725,8 +729,8 @@ def test_array_i8_dtype(self, arr1d):
725
729
result = np .array (arr , dtype = np .int64 )
726
730
tm .assert_numpy_array_equal (result , expected )
727
731
728
- # check that we are still making copies when setting copy=False
729
- result = np .array (arr , dtype = "i8" , copy = False )
732
+ # check that we are still making copies when setting copy=copy_false
733
+ result = np .array (arr , dtype = "i8" , copy = copy_false )
730
734
assert result .base is not expected .base
731
735
assert result .base is None
732
736
@@ -952,13 +956,14 @@ def test_int_properties(self, timedelta_index, propname):
952
956
953
957
def test_array_interface (self , timedelta_index ):
954
958
arr = timedelta_index ._data
959
+ copy_false = None if np_version_gt2 else False
955
960
956
961
# default asarray gives the same underlying data
957
962
result = np .asarray (arr )
958
963
expected = arr ._ndarray
959
964
assert result is expected
960
965
tm .assert_numpy_array_equal (result , expected )
961
- result = np .array (arr , copy = False )
966
+ result = np .array (arr , copy = copy_false )
962
967
assert result is expected
963
968
tm .assert_numpy_array_equal (result , expected )
964
969
@@ -967,7 +972,7 @@ def test_array_interface(self, timedelta_index):
967
972
expected = arr ._ndarray
968
973
assert result is expected
969
974
tm .assert_numpy_array_equal (result , expected )
970
- result = np .array (arr , dtype = "timedelta64[ns]" , copy = False )
975
+ result = np .array (arr , dtype = "timedelta64[ns]" , copy = copy_false )
971
976
assert result is expected
972
977
tm .assert_numpy_array_equal (result , expected )
973
978
result = np .array (arr , dtype = "timedelta64[ns]" )
0 commit comments