Skip to content

Return an empty frame when Yahoo has no session in the requested window - #166

Merged
stefan-jansen merged 3 commits into
mainfrom
fix/yahoo-empty-range
Nov 25, 2026
Merged

stefan-jansen merged 3 commits into
mainfrom
fix/yahoo-empty-range

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

Closes #164

What changes

A ranged Yahoo download for a known symbol over a window without a session (a weekend, an exchange holiday) now returns the canonical empty OHLCV frame, as the other providers do and as StorageManager.update and the loaders expect (is_empty()). SymbolNotFoundError is kept for a symbol Yahoo does not know or has no recent sessions for.

yfinance 1.5.2 reports the two cases differently: an unknown symbol fails with YFTzMissingError, a known symbol without bars in the window with YFPricesMissingError. Delisted symbols also produce the latter, so after an empty download the provider requests the last month of daily bars once and returns an empty frame only when Yahoo has recent sessions. A rate limit during that request is a RateLimitError, not a missing symbol.

  • fetch_ohlcv: empty session window -> empty canonical frame. A response holding only the current session's null-price placeholder row is the same case.
  • fetch_adjusted_close: empty typed frame (timestamp, symbol, close) with provenance metadata set.
  • docs/providers/yahoo.md documents the distinction.
  • tests/test_yahoo_provider.py::test_a_response_of_nothing_but_placeholders_is_not_data asserted the old behaviour (SymbolNotFoundError for a placeholder-only response from AAPL). It is now ..._is_an_empty_window and asserts the empty canonical frame.

Tests

Each test names the error it prevents. Run against origin/main (a367050) and this branch:

Test main branch
test_a_weekend_returns_the_canonical_empty_frame FAILED passed
test_a_window_holding_only_the_current_session_placeholder_is_empty FAILED passed
test_adjusted_close_over_a_weekend_returns_an_empty_typed_frame FAILED passed
test_a_rate_limit_while_confirming_the_symbol_is_a_rate_limit FAILED passed
test_a_response_of_nothing_but_placeholders_is_an_empty_window FAILED passed
test_an_unknown_symbol_over_a_weekend_is_still_not_found (guard) passed passed
test_a_symbol_without_recent_prices_is_still_not_found (guard) passed passed

The guards fail on an over-broad fix (treating every YFPricesMissingError as empty without the recent-session check); checked by mutation. Integration test test_window_without_sessions_is_empty_not_unknown (live, -m integration) passes.

Live check against Yahoo

origin/main: SPY over 2025-06-07..08, SPY on 2025-12-25 and fetch_adjusted_close over the weekend all raised SymbolNotFoundError.

This branch:

SPY       2025-06-07..2025-06-08 weekend                    -> 0 rows, schema=['timestamp', 'symbol', 'open', 'high', 'low', 'close', 'volume']
SPY       2025-12-25..2025-12-25 Christmas holiday          -> 0 rows, schema=['timestamp', 'symbol', 'open', 'high', 'low', 'close', 'volume']
SPY       2025-06-02..2025-06-06 full week                  -> 5 rows, schema=['timestamp', 'symbol', 'open', 'high', 'low', 'close', 'volume']
NOPE_ZZZ  2025-06-07..2025-06-08 unknown symbol, weekend    -> SymbolNotFoundError: yahoo: Symbol 'NOPE_ZZZ' not found or invalid
NOPE_ZZZ  2025-06-02..2025-06-06 unknown symbol, full week  -> SymbolNotFoundError: yahoo: Symbol 'NOPE_ZZZ' not found or invalid
fetch_adjusted_close SPY weekend -> 0 rows, ['timestamp', 'symbol', 'close']

Not changed

  • fetch_batch_ohlcv is untouched.
  • A YFPricesMissingError caused by a transient HTTP error, followed by a successful recent-session request, now yields an empty frame rather than an error.

Gates

ruff check, ruff format --check, ty check, pytest tests with coverage (4650 passed, 1 skipped), the -W error::ResourceWarning lane (4650 passed), mkdocs build --strict, uv build, actionlint, pre-commit run --all-files: all pass. No pre-existing failures.

Stefan Jansen and others added 3 commits November 24, 2026 18:55
A ranged Yahoo download for a known symbol over a weekend or exchange holiday
raised SymbolNotFoundError, so callers could not tell an empty window from an
unknown symbol. The other providers return the canonical empty frame for an
empty range, and StorageManager.update and the loaders already test
is_empty().

yfinance reports the two cases differently: an unknown symbol fails with
YFTzMissingError, a known symbol without bars in the window with
YFPricesMissingError. Delisted symbols also raise the latter, so after an
empty download the provider asks for the last month of daily bars and only
returns an empty frame when Yahoo has recent sessions for the symbol.
fetch_adjusted_close returns an empty typed frame the same way, and a
placeholder-only response (the current session's null-price row) is now an
empty window instead of a missing symbol.

Closes #164
@stefan-jansen
stefan-jansen merged commit f6f86d4 into main Nov 25, 2026
33 checks passed
@stefan-jansen
stefan-jansen deleted the fix/yahoo-empty-range branch November 25, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Yahoo: a valid symbol over a range with no sessions raises SymbolNotFoundError

1 participant