Skip to content

Commit 78819d7

Browse files
committed
Fix(history, utils): Correct 30m interval alignment and filtering\n\n- Updated history.py to pass the correct 'interval' (30m) to post-processing functions instead of the hacked 'params["interval"]' (15m).\n- Updated utils.py to use the interval duration for the start-time check, ensuring valid candles overlapping the market open (e.g. 09:00-09:30 for 09:15 open) are not dropped.
1 parent 132a029 commit 78819d7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

yfinance/scrapers/history.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,16 @@ def history(self, period=None, interval="1d",
320320
})
321321

322322
# Note: ordering is important. If you change order, run the tests!
323-
quotes = utils.set_df_tz(quotes, params["interval"], tz_exchange)
324-
quotes = utils.fix_Yahoo_dst_issue(quotes, params["interval"])
323+
quotes = utils.set_df_tz(quotes, interval, tz_exchange)
324+
quotes = utils.fix_Yahoo_dst_issue(quotes, interval)
325325
intraday = params["interval"][-1] in ("m", 'h')
326326
if not prepost and intraday and "tradingPeriods" in self._history_metadata:
327327
tps = self._history_metadata["tradingPeriods"]
328328
if not isinstance(tps, pd.DataFrame):
329329
self._history_metadata = utils.format_history_metadata(self._history_metadata, tradingPeriodsOnly=True)
330330
self._history_metadata_formatted = True
331331
tps = self._history_metadata["tradingPeriods"]
332-
quotes = utils.fix_Yahoo_returning_prepost_unrequested(quotes, params["interval"], tps)
332+
quotes = utils.fix_Yahoo_returning_prepost_unrequested(quotes, interval, tps)
333333
if quotes.empty:
334334
msg = f'{self.ticker}: OHLC after cleaning: EMPTY'
335335
elif len(quotes) == 1:

yfinance/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,8 @@ def fix_Yahoo_returning_prepost_unrequested(quotes, interval, tradingPeriods):
601601
quotes.index = idx
602602
# "end" = end of regular trading hours (including any auction)
603603
f_drop = quotes.index >= quotes["end"]
604-
f_drop = f_drop | (quotes.index < quotes["start"])
604+
td = _interval_to_timedelta(interval)
605+
f_drop = f_drop | (quotes.index + td <= quotes["start"])
605606
if f_drop.any():
606607
# When printing report, ignore rows that were already NaNs:
607608
# f_na = quotes[["Open","Close"]].isna().all(axis=1)

0 commit comments

Comments
 (0)