File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 77 datetime ,
88 time ,
99 timedelta ,
10+ timezone ,
1011)
1112import re
1213
@@ -2702,6 +2703,27 @@ def test_loc_indexer_length_one(self):
27022703 df .loc [np .array ([True ], dtype = np .bool_ ), ["a" ]] = df ["b" ].copy ()
27032704 tm .assert_frame_equal (df , expected )
27042705
2706+ def test_loc_setitem_bool_mask_tzaware_scalar_with_expansion (self ):
2707+ # GH#55423
2708+
2709+ df = DataFrame ([{"id" : 1 }, {"id" : 2 }, {"id" : 3 }])
2710+ _time = datetime .fromtimestamp (1695887042 , tz = timezone .utc )
2711+
2712+ df .loc [df .id >= 2 , "time" ] = _time
2713+
2714+ assert isinstance (df ["time" ].dtype , pd .DatetimeTZDtype )
2715+ assert str (df ["time" ].dtype .tz ) == "UTC"
2716+
2717+ expected_time = Timestamp (_time )
2718+ expected = DataFrame (
2719+ {
2720+ "id" : [1 , 2 , 3 ],
2721+ "time" : [pd .NaT , expected_time , expected_time ],
2722+ }
2723+ )
2724+ expected ["time" ] = expected ["time" ].astype ("datetime64[us, UTC]" )
2725+ tm .assert_frame_equal (df , expected )
2726+
27052727
27062728class TestLocListlike :
27072729 @pytest .mark .parametrize ("box" , [lambda x : x , np .asarray , list ])
You can’t perform that action at this time.
0 commit comments