1010from  pandas .core .dtypes .common  import  is_float_dtype , is_integer_dtype 
1111
1212import  pandas  as  pd 
13- from  pandas  import  DataFrame , Index , NaT , Series , date_range 
13+ from  pandas  import  DataFrame , Index , NaT , Series , date_range ,  offsets ,  timedelta_range 
1414import  pandas ._testing  as  tm 
1515from  pandas .core .indexing  import  maybe_numeric_slice , non_reducing_slice 
1616from  pandas .tests .indexing .common  import  _mklbl 
@@ -970,19 +970,22 @@ class TestDatetimelikeCoercion:
970970 @pytest .mark .parametrize ("indexer" , [setitem , loc , iloc ]) 
971971 def  test_setitem_dt64_string_scalar (self , tz_naive_fixture , indexer ):
972972 # dispatching _can_hold_element to underling DatetimeArray 
973-  # TODO(EA2D) use tz_naive_fixture once DatetimeBlock is backed by DTA 
974973 tz  =  tz_naive_fixture 
975974
976975 dti  =  date_range ("2016-01-01" , periods = 3 , tz = tz )
977976 ser  =  Series (dti )
978977
979978 values  =  ser ._values 
980979
981-  indexer (ser )[0 ] =  "2018-01-01" 
980+  newval  =  "2018-01-01" 
981+  values ._validate_setitem_value (newval )
982+ 
983+  indexer (ser )[0 ] =  newval 
982984
983985 if  tz  is  None :
984986 # TODO(EA2D): we can make this no-copy in tz-naive case too 
985987 assert  ser .dtype  ==  dti .dtype 
988+  assert  ser ._values ._data  is  values ._data 
986989 else :
987990 assert  ser ._values  is  values 
988991
@@ -993,7 +996,6 @@ def test_setitem_dt64_string_scalar(self, tz_naive_fixture, indexer):
993996 @pytest .mark .parametrize ("indexer" , [setitem , loc , iloc ]) 
994997 def  test_setitem_dt64_string_values (self , tz_naive_fixture , indexer , key , box ):
995998 # dispatching _can_hold_element to underling DatetimeArray 
996-  # TODO(EA2D) use tz_naive_fixture once DatetimeBlock is backed by DTA 
997999 tz  =  tz_naive_fixture 
9981000
9991001 if  isinstance (key , slice ) and  indexer  is  loc :
@@ -1012,9 +1014,44 @@ def test_setitem_dt64_string_values(self, tz_naive_fixture, indexer, key, box):
10121014 if  tz  is  None :
10131015 # TODO(EA2D): we can make this no-copy in tz-naive case too 
10141016 assert  ser .dtype  ==  dti .dtype 
1017+  assert  ser ._values ._data  is  values ._data 
10151018 else :
10161019 assert  ser ._values  is  values 
10171020
1021+  @pytest .mark .parametrize ("scalar" , ["3 Days" , offsets .Hour (4 )]) 
1022+  @pytest .mark .parametrize ("indexer" , [setitem , loc , iloc ]) 
1023+  def  test_setitem_td64_scalar (self , indexer , scalar ):
1024+  # dispatching _can_hold_element to underling TimedeltaArray 
1025+  tdi  =  timedelta_range ("1 Day" , periods = 3 )
1026+  ser  =  Series (tdi )
1027+ 
1028+  values  =  ser ._values 
1029+  values ._validate_setitem_value (scalar )
1030+ 
1031+  indexer (ser )[0 ] =  scalar 
1032+  assert  ser ._values ._data  is  values ._data 
1033+ 
1034+  @pytest .mark .parametrize ("box" , [list , np .array , pd .array ]) 
1035+  @pytest .mark .parametrize ( 
1036+  "key" , [[0 , 1 ], slice (0 , 2 ), np .array ([True , True , False ])] 
1037+  ) 
1038+  @pytest .mark .parametrize ("indexer" , [setitem , loc , iloc ]) 
1039+  def  test_setitem_td64_string_values (self , indexer , key , box ):
1040+  # dispatching _can_hold_element to underling TimedeltaArray 
1041+  if  isinstance (key , slice ) and  indexer  is  loc :
1042+  key  =  slice (0 , 1 )
1043+ 
1044+  tdi  =  timedelta_range ("1 Day" , periods = 3 )
1045+  ser  =  Series (tdi )
1046+ 
1047+  values  =  ser ._values 
1048+ 
1049+  newvals  =  box (["10 Days" , "44 hours" ])
1050+  values ._validate_setitem_value (newvals )
1051+ 
1052+  indexer (ser )[key ] =  newvals 
1053+  assert  ser ._values ._data  is  values ._data 
1054+ 
10181055
10191056def  test_extension_array_cross_section ():
10201057 # A cross-section of a homogeneous EA should be an EA 
0 commit comments