@@ -2761,6 +2761,26 @@ def test_loc_setitem_uint8_upcast(value):
2761
2761
tm .assert_frame_equal (df , expected )
2762
2762
2763
2763
2764
+ @pytest .mark .parametrize (
2765
+ "fill_val,exp_dtype" ,
2766
+ [
2767
+ (Timestamp ("2022-01-06" ), "datetime64[ns]" ),
2768
+ (Timestamp ("2022-01-07" , tz = "US/Eastern" ), "datetime64[ns, US/Eastern]" ),
2769
+ ],
2770
+ )
2771
+ def test_loc_setitem_using_datetimelike_str_as_index (fill_val , exp_dtype ):
2772
+
2773
+ data = ["2022-01-02" , "2022-01-03" , "2022-01-04" , fill_val .date ()]
2774
+ index = DatetimeIndex (data , tz = fill_val .tz , dtype = exp_dtype )
2775
+ df = DataFrame ([10 , 11 , 12 , 14 ], columns = ["a" ], index = index )
2776
+ # adding new row using an unexisting datetime-like str index
2777
+ df .loc ["2022-01-08" , "a" ] = 13
2778
+
2779
+ data .append ("2022-01-08" )
2780
+ expected_index = DatetimeIndex (data , dtype = exp_dtype )
2781
+ tm .assert_index_equal (df .index , expected_index , exact = True )
2782
+
2783
+
2764
2784
class TestLocSeries :
2765
2785
@pytest .mark .parametrize ("val,expected" , [(2 ** 63 - 1 , 3 ), (2 ** 63 , 4 )])
2766
2786
def test_loc_uint64 (self , val , expected ):
0 commit comments