|  | 
| 7 | 7 |     datetime, | 
| 8 | 8 |     time, | 
| 9 | 9 |     timedelta, | 
|  | 10 | +    timezone, | 
| 10 | 11 | ) | 
| 11 | 12 | import re | 
| 12 | 13 | 
 | 
| @@ -2702,6 +2703,30 @@ def test_loc_indexer_length_one(self): | 
| 2702 | 2703 |         df.loc[np.array([True], dtype=np.bool_), ["a"]] = df["b"].copy() | 
| 2703 | 2704 |         tm.assert_frame_equal(df, expected) | 
| 2704 | 2705 | 
 | 
|  | 2706 | +    def test_loc_setitem_bool_mask_tzaware_scalar_with_expansion(self): | 
|  | 2707 | +        # GH#55423 | 
|  | 2708 | +        # Test that setitem with boolean mask and column expansion | 
|  | 2709 | +        # preserves timezone-aware dtype when assigning scalar datetime | 
|  | 2710 | + | 
|  | 2711 | +        df = DataFrame([{"id": 1}, {"id": 2}, {"id": 3}]) | 
|  | 2712 | +        _time = datetime.fromtimestamp(1695887042, tz=timezone.utc) | 
|  | 2713 | + | 
|  | 2714 | +        df.loc[df.id >= 2, "time"] = _time | 
|  | 2715 | + | 
|  | 2716 | +        # Verify dtype is timezone-aware datetime, not object | 
|  | 2717 | +        assert isinstance(df["time"].dtype, pd.DatetimeTZDtype) | 
|  | 2718 | +        assert str(df["time"].dtype.tz) == "UTC" | 
|  | 2719 | + | 
|  | 2720 | +        expected_time = Timestamp(_time) | 
|  | 2721 | +        expected = DataFrame( | 
|  | 2722 | +            { | 
|  | 2723 | +                "id": [1, 2, 3], | 
|  | 2724 | +                "time": [pd.NaT, expected_time, expected_time], | 
|  | 2725 | +            } | 
|  | 2726 | +        ) | 
|  | 2727 | +        expected["time"] = expected["time"].astype("datetime64[us, UTC]") | 
|  | 2728 | +        tm.assert_frame_equal(df, expected) | 
|  | 2729 | + | 
| 2705 | 2730 | 
 | 
| 2706 | 2731 | class TestLocListlike: | 
| 2707 | 2732 |     @pytest.mark.parametrize("box", [lambda x: x, np.asarray, list]) | 
|  | 
0 commit comments