From f1ad8f0061ca5ae17da96c45062f33c475a10327 Mon Sep 17 00:00:00 2001 From: ValueRaider Date: Fri, 21 Oct 2022 12:43:50 +0100 Subject: [PATCH] Fix tz-localize when DST-ambiguous --- yfinance/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yfinance/base.py b/yfinance/base.py index b2bed979f..62fcfaa36 100644 --- a/yfinance/base.py +++ b/yfinance/base.py @@ -313,7 +313,9 @@ def history(self, period="1mo", interval="1d", elif params["interval"] == "1h": pass else: - df.index = _pd.to_datetime(df.index.date).tz_localize(tz_exchange) + # If a midnight is during DST transition hour when clocks roll back, + # meaning clock hits midnight twice, then use the 2nd (ambiguous=True) + df.index = _pd.to_datetime(df.index.date).tz_localize(tz_exchange, ambiguous=True) df.index.name = "Date" # duplicates and missing rows cleanup