Skip to content

Commit

Permalink
Merge pull request #1177 from ranaroussi/fix/dst-nonexistent
Browse files Browse the repository at this point in the history
Fix localizing midnight when non-existent (DST) #1174
  • Loading branch information
ValueRaider committed Nov 22, 2022
2 parents 96e4532 + 2970d94 commit b856041
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions yfinance/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ def history(self, period="1mo", interval="1d",
if not intraday:
# If localizing a midnight during DST transition hour when clocks roll back,
# meaning clock hits midnight twice, then use the 2nd (ambiguous=True)
quotes.index = _pd.to_datetime(quotes.index.date).tz_localize(tz_exchange, ambiguous=True)
quotes.index = _pd.to_datetime(quotes.index.date).tz_localize(tz_exchange, ambiguous=True, nonexistent='shift_forward')
if dividends.shape[0] > 0:
dividends.index = _pd.to_datetime(dividends.index.date).tz_localize(tz_exchange, ambiguous=True)
dividends.index = _pd.to_datetime(dividends.index.date).tz_localize(tz_exchange, ambiguous=True, nonexistent='shift_forward')
if splits.shape[0] > 0:
splits.index = _pd.to_datetime(splits.index.date).tz_localize(tz_exchange, ambiguous=True)
splits.index = _pd.to_datetime(splits.index.date).tz_localize(tz_exchange, ambiguous=True, nonexistent='shift_forward')

# Combine
df = quotes.sort_index()
Expand Down
2 changes: 1 addition & 1 deletion yfinance/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def _reindex_events(df, new_index, data_col_name):
new_index = None

if new_index is not None:
new_index = new_index.tz_localize(df.index.tz, ambiguous=True)
new_index = new_index.tz_localize(df.index.tz, ambiguous=True, nonexistent='shift_forward')
df_sub = _reindex_events(df_sub, new_index, data_col)
df = df_main.join(df_sub)

Expand Down

0 comments on commit b856041

Please sign in to comment.