Repository: pandas-dev/pandas
File: pandas/tests/indexes/datetimes/test_date_range.py (Python)

Code before:
        exp = DatetimeIndex(
            ["2021-12-31 00:00:01", "2022-12-31 00:00:01"],
            dtype=f"M8[{unit}]",
            freq="YE",
        )
        tm.assert_index_equal(rng, exp)

    def test_date_range_negative_freq_year_end_inbounds(self, unit):
        # GH#56147
        rng = date_range(
            start="2023-10-31 00:00:00",
            end="2021-10-31 00:00:00",
            freq="-1YE",
            unit=unit,
        )
        exp = DatetimeIndex(
            ["2022-12-31 00:00:00", "2021-12-31 00:00:00"],
            dtype=f"M8[{unit}]",
            freq="-1YE",
        )
        tm.assert_index_equal(rng, exp)

    def test_date_range_tzaware_endpoints_accept_ambiguous(self):
        # With tz-aware endpoints and a calendar offset (MS),
        # date_range should accept `ambiguous=True` and produce
        # the same result as passing tz explicitly with naive endpoints.
        start = Timestamp("1916-08-01", tz="Europe/Oslo")
        end = Timestamp("1916-12-01", tz="Europe/Oslo")
        res = date_range(start, end, freq="MS", ambiguous=True)
        exp = date_range(
            "1916-08-01", "1916-12-01", freq="MS", tz="Europe/Oslo", ambiguous=True
        )
        tm.assert_index_equal(res, exp)


Review comment (suggestion):
```suggestion
        # https://github.com/pandas-dev/pandas/issues/52908
```

Code after:
        exp = DatetimeIndex(
            ["2021-12-31 00:00:01", "2022-12-31 00:00:01"],
            dtype=f"M8[{unit}]",
            freq="YE",
        )
        tm.assert_index_equal(rng, exp)

    def test_date_range_negative_freq_year_end_inbounds(self, unit):
        # GH#56147
        rng = date_range(
            start="2023-10-31 00:00:00",
            end="2021-10-31 00:00:00",
            freq="-1YE",
            unit=unit,
        )
        exp = DatetimeIndex(
            ["2022-12-31 00:00:00", "2021-12-31 00:00:00"],
            dtype=f"M8[{unit}]",
            freq="-1YE",
        )
        tm.assert_index_equal(rng, exp)

    def test_date_range_tzaware_endpoints_accept_ambiguous(self):
        # https://github.com/pandas-dev/pandas/issues/52908
        start = Timestamp("1916-08-01", tz="Europe/Oslo")
        end = Timestamp("1916-12-01", tz="Europe/Oslo")
        res = date_range(start, end, freq="MS", ambiguous=True)
        exp = date_range(
            "1916-08-01", "1916-12-01", freq="MS", tz="Europe/Oslo", ambiguous=True
        )
        tm.assert_index_equal(res, exp)

    def test_date_range_tzaware_endpoints_accept_nonexistent(self):
        # Europe/London spring-forward: 2015-03-29 01:30 does not exist.
        tz = "Europe/London"
        start = Timestamp("2015-03-28 01:30", tz=tz)
        end = Timestamp("2015-03-30 01:30", tz=tz)

        result = date_range(start, end, freq="D", nonexistent="shift_forward")

        # Build expected by generating naive daily times, then tz_localize so
        # the nonexistent handling is applied during localization.
        expected = date_range(
            "2015-03-28 01:30", "2015-03-30 01:30", freq="D"
        ).tz_localize(tz, nonexistent="shift_forward")
        tm.assert_index_equal(result, expected)