1212 Timestamp ,
1313)
1414from pandas ._libs .tslibs import to_offset
15+ from pandas .compat .numpy import np_version_gt2
1516
1617from pandas .core .dtypes .dtypes import PeriodDtype
1718
@@ -640,13 +641,14 @@ def test_round(self, arr1d):
640641
641642 def test_array_interface (self , datetime_index ):
642643 arr = datetime_index ._data
644+ copy_false = None if np_version_gt2 else False
643645
644646 # default asarray gives the same underlying data (for tz naive)
645647 result = np .asarray (arr )
646648 expected = arr ._ndarray
647649 assert result is expected
648650 tm .assert_numpy_array_equal (result , expected )
649- result = np .array (arr , copy = False )
651+ result = np .array (arr , copy = copy_false )
650652 assert result is expected
651653 tm .assert_numpy_array_equal (result , expected )
652654
@@ -655,7 +657,7 @@ def test_array_interface(self, datetime_index):
655657 expected = arr ._ndarray
656658 assert result is expected
657659 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 )
659661 assert result is expected
660662 tm .assert_numpy_array_equal (result , expected )
661663 result = np .array (arr , dtype = "datetime64[ns]" )
@@ -698,6 +700,7 @@ def test_array_tz(self, arr1d):
698700 # GH#23524
699701 arr = arr1d
700702 dti = self .index_cls (arr1d )
703+ copy_false = None if np_version_gt2 else False
701704
702705 expected = dti .asi8 .view ("M8[ns]" )
703706 result = np .array (arr , dtype = "M8[ns]" )
@@ -706,17 +709,18 @@ def test_array_tz(self, arr1d):
706709 result = np .array (arr , dtype = "datetime64[ns]" )
707710 tm .assert_numpy_array_equal (result , expected )
708711
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 )
711714 assert result .base is expected .base
712715 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 )
714717 assert result .base is expected .base
715718 assert result .base is not None
716719
717720 def test_array_i8_dtype (self , arr1d ):
718721 arr = arr1d
719722 dti = self .index_cls (arr1d )
723+ copy_false = None if np_version_gt2 else False
720724
721725 expected = dti .asi8
722726 result = np .array (arr , dtype = "i8" )
@@ -725,8 +729,8 @@ def test_array_i8_dtype(self, arr1d):
725729 result = np .array (arr , dtype = np .int64 )
726730 tm .assert_numpy_array_equal (result , expected )
727731
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 )
730734 assert result .base is not expected .base
731735 assert result .base is None
732736
@@ -952,13 +956,14 @@ def test_int_properties(self, timedelta_index, propname):
952956
953957 def test_array_interface (self , timedelta_index ):
954958 arr = timedelta_index ._data
959+ copy_false = None if np_version_gt2 else False
955960
956961 # default asarray gives the same underlying data
957962 result = np .asarray (arr )
958963 expected = arr ._ndarray
959964 assert result is expected
960965 tm .assert_numpy_array_equal (result , expected )
961- result = np .array (arr , copy = False )
966+ result = np .array (arr , copy = copy_false )
962967 assert result is expected
963968 tm .assert_numpy_array_equal (result , expected )
964969
@@ -967,7 +972,7 @@ def test_array_interface(self, timedelta_index):
967972 expected = arr ._ndarray
968973 assert result is expected
969974 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 )
971976 assert result is expected
972977 tm .assert_numpy_array_equal (result , expected )
973978 result = np .array (arr , dtype = "timedelta64[ns]" )
0 commit comments