Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion collectors/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ def _fred_release_dates(release_id: int, api_key: str) -> list[str]:
``include_release_dates_with_no_data=true`` makes FRED include FUTURE
scheduled dates (which have no data yet). Returns ``[]`` on failure; the
caller filters to the forward horizon.

``sort_order=desc`` returns the furthest-future scheduled dates first, so the
limit must exceed the count of ALL future-scheduled dates or the NEAREST ones
get truncated off the bottom — that silently dropped near-term weekly claims
(a ~7-week gap) at limit=24. 130 comfortably covers a year-plus of any
cadence (weekly ≈ 52/yr) while the caller still trims to the 180d horizon.
"""
try:
params = {
Expand All @@ -459,7 +465,7 @@ def _fred_release_dates(release_id: int, api_key: str) -> list[str]:
"file_type": "json",
"include_release_dates_with_no_data": "true",
"sort_order": "desc",
"limit": 24,
"limit": 130,
}
resp = requests.get(_FRED_RELEASE_DATES_BASE, params=params, timeout=_FRED_TIMEOUT)
resp.raise_for_status()
Expand Down
27 changes: 27 additions & 0 deletions tests/test_release_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ def test_build_release_calendar_empty_without_key(monkeypatch):
assert list(df.columns) == _CAL_COLS


def test_fred_release_dates_requests_enough_future_dates(monkeypatch):
"""Regression: the FRED query must request enough desc dates to reach the
NEAREST future ones. sort_order=desc returns furthest-future first, so a
small limit truncated near-term weekly claims (the ~7-week ICSA gap). Pin a
floor on the limit + the future-dates flag so a shrink re-surfaces visibly.
"""
captured = {}

class _Resp:
def raise_for_status(self):
pass

def json(self):
return {"release_dates": [{"date": "2026-06-11"}]}

def _fake_get(url, params=None, timeout=None):
captured.update(params or {})
return _Resp()

monkeypatch.setattr(macro.requests, "get", _fake_get)
out = macro._fred_release_dates(10, "fake-key")
assert out == ["2026-06-11"]
assert captured["include_release_dates_with_no_data"] == "true"
assert captured["sort_order"] == "desc"
assert captured["limit"] >= 120 # must cover a year-plus of weekly cadence


def test_write_release_calendar_puts_parquet(monkeypatch):
df = pd.DataFrame(
[{"date": "2026-06-11", "kind": "release", "series_id": "CPIAUCSL",
Expand Down
Loading