ZipLime commited on
Commit
6737873
·
verified ·
1 Parent(s): 8863726

Update the FOMC events dataset

Browse files
PIPELINE.md CHANGED
@@ -213,8 +213,16 @@ python -m recipe.cli verify # the gate and the manifest, over what is
213
  python -m recipe.cli publish # mirror to Hugging Face, gate first
214
  ```
215
 
216
- The document cache is not published. A scheduled run restores the tables from
217
- the dataset repository and fetches only what it does not already have.
 
 
 
 
 
 
 
 
218
 
219
  ## Scheduling
220
 
 
213
  python -m recipe.cli publish # mirror to Hugging Face, gate first
214
  ```
215
 
216
+ The document cache is not published, so a scheduled run starts from the tables
217
+ in the dataset repository instead. A finished auction's result artifact cannot
218
+ change, so a run that already holds the row does not ask TreasuryDirect for it
219
+ again: the first build reads 6 229 artifacts in about thirty-five minutes, and
220
+ every run after it reuses them and finishes in **four seconds**.
221
+
222
+ Only rows whose instant came from an artifact are reused. A row dated to the
223
+ end of its day is one whose artifact was never found, and the next run looks
224
+ again in case the Treasury has since published one. `--rebuild` ignores held
225
+ rows entirely, which is what a parser change needs.
226
 
227
  ## Scheduling
228
 
README.md CHANGED
@@ -276,6 +276,21 @@ the public domain. The Department does not endorse, certify or verify this
276
  dataset. The additions here — the release instants, the long-form curves, the
277
  validation — are Apache-2.0.
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  ## Related
280
 
281
  [us-economic-events](https://huggingface.co/datasets/ZipLime/us-economic-events) ·
 
276
  dataset. The additions here — the release instants, the long-form curves, the
277
  validation — are Apache-2.0.
278
 
279
+ ## Rebuilding it
280
+
281
+ The first build reads 6 229 auction artifacts and takes about thirty-five
282
+ minutes. Every run after that reuses them — a finished auction's result cannot
283
+ change — and finishes in **four seconds**, having asked the Treasury only for
284
+ the auction query and the current year of each rate feed.
285
+
286
+ ```bash
287
+ python -m recipe.cli build # incremental
288
+ python -m recipe.cli build --rebuild # read everything again; what a parser change needs
289
+ ```
290
+
291
+ The two produce identical tables; `tests/test_auctions.py` covers which rows
292
+ are eligible for reuse and why a date-precision row is not.
293
+
294
  ## Related
295
 
296
  [us-economic-events](https://huggingface.co/datasets/ZipLime/us-economic-events) ·
data/auction_announcements/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3edc55fb0c5ec33e820741609eb0b7dbe1fbcb1459c55b13c141f49a781a5f73
3
- size 752074
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:142a2412413a95358533234e809e4f42e81495f447ae85a7a15fbce3e7327daa
3
+ size 481456
data/auction_calendar/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f4cef6ff94864e03f577fa18005d1c20659a8169fce806eaf284c793e8e5769c
3
- size 691150
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dcbf15b1fdc7d61266c3b26e539c4d0d2caa8a584c10ff9ae739c9d14f8b97f7
3
+ size 419757
data/auction_results/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f33aba904297b388b76556053db3f60730e6732f2e40c9825273f9048c12d875
3
- size 1615688
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:456c69c71cce592872aa26a8d925b67706096ee7d7ba4cb4eeceffb94a062271
3
+ size 1618434
data/bill_rates/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:64ee3c01dde02b38491657e904cd538b8562f08089bce6d3cce3a02fdf9c77b2
3
- size 368221
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb6db92ebca2f559d60e2b0eaec531819182e7cdec578fffee77019aab6f9565
3
+ size 368148
data/curve_features/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fa297ebbf0bd59c5bc98116a515b0ec1c4a9a05a7cafdf54387a82d99f581b0e
3
  size 189724
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21cc853704796423906651ad046d6f960314c0ead841b184521b4f62afc779f1
3
  size 189724
data/nominal_yield_curve/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b8a07e06764dd34fbe8dde9796ef4e5509224d7c9dd5a93008e4482d60aab741
3
- size 723747
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:18c04f88223bea9d99d3c13a3efb0b545bcf29ad0d1b0c18b8f2b13e8356e5dc
3
+ size 716653
data/pit/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:95d4d926c2e660bfec424be16b9dac6ddfb185cbab7306c0700a0f4d699c0758
3
  size 2724267
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d87656c5f099116fe05942612b4b06a3acc00f540fde269ef539c4414233d84
3
  size 2724267
data/pit/us_treasury_events.delta/_delta_log/00000000000000000000.json CHANGED
@@ -1,4 +1,4 @@
1
- {"commitInfo":{"timestamp":1789279497921,"operation":"WRITE","operationParameters":{"mode":"Overwrite"},"engineInfo":"delta-rs:py-1.6.2","operationMetrics":{"execution_time_ms":124,"num_added_files":1,"num_added_rows":268960,"num_partitions":0,"num_removed_files":0},"clientVersion":"delta-rs.py-1.6.2"}}
2
  {"protocol":{"minReaderVersion":1,"minWriterVersion":2}}
3
- {"metaData":{"id":"f95af2fe-97d4-4c4a-a5da-16b99eab5308","name":null,"description":null,"format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"entity_id\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"event_date\",\"type\":\"date\",\"nullable\":true,\"metadata\":{}},{\"name\":\"knowledge_date\",\"type\":\"timestamp\",\"nullable\":true,\"metadata\":{}},{\"name\":\"subset\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"record_id\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"actual\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"previous\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"change\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"forecast\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"unit\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"value_method\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"knowledge_time_precision\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"source_url\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"parser_version\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"ingested_at\",\"type\":\"timestamp\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":[],"createdTime":1789279497799,"configuration":{}}}
4
- {"add":{"path":"part-00000-c8ebf74b-2931-4d5f-a1fc-89a9f11538d2-c000.snappy.parquet","partitionValues":{},"size":4422313,"modificationTime":1789279497920,"dataChange":true,"stats":"{\"numRecords\":268960,\"minValues\":{\"entity_id\":\"UST_AUCTION_101D_CMB_ALLOTMENT_AT_HIGH_PCT\",\"knowledge_time_precision\":\"date\",\"record_id\":\"UST_1979-10-31_912827KC5_RES\",\"value_method\":\"derived\",\"knowledge_date\":\"1979-11-01T04:59:59Z\",\"change\":-98.69,\"unit\":\"percent\",\"actual\":-1.91,\"source_url\":\"https://home.treasury.gov/resource-center/data-chart-center/inte\",\"ingested_at\":\"2026-09-13T06:04:57.223592Z\",\"subset\":\"auction_results\",\"event_date\":\"1979-10-31\",\"parser_version\":\"1.0.0\",\"previous\":-1.91},\"maxValues\":{\"ingested_at\":\"2026-09-13T06:04:57.223592Z\",\"actual\":100.0,\"event_date\":\"2026-09-11\",\"previous\":100.0,\"entity_id\":\"UST_REAL_LT_REAL_AVERAGE\",\"value_method\":\"reported\",\"knowledge_date\":\"2026-09-11T22:00:00Z\",\"knowledge_time_precision\":\"modeled_conservative\",\"source_url\":\"https://www.treasurydirect.gov/xml/R_20260910_3.xml\",\"unit\":\"ratio\",\"parser_version\":\"1.0.0\",\"subset\":\"real_yield_curve\",\"change\":98.15,\"record_id\":\"real_2026-09-11_7Y\"},\"nullCount\":{\"forecast\":268960,\"subset\":0,\"knowledge_time_precision\":0,\"change\":1287,\"source_url\":0,\"entity_id\":0,\"previous\":1287,\"actual\":0,\"event_date\":0,\"value_method\":0,\"ingested_at\":0,\"record_id\":0,\"unit\":0,\"knowledge_date\":0,\"parser_version\":0}}","tags":null,"baseRowId":null,"defaultRowCommitVersion":null,"clusteringProvider":null}}
 
1
+ {"commitInfo":{"timestamp":1789280105024,"operation":"WRITE","operationParameters":{"mode":"Overwrite"},"engineInfo":"delta-rs:py-1.6.2","operationMetrics":{"execution_time_ms":124,"num_added_files":1,"num_added_rows":268960,"num_partitions":0,"num_removed_files":0},"clientVersion":"delta-rs.py-1.6.2"}}
2
  {"protocol":{"minReaderVersion":1,"minWriterVersion":2}}
3
+ {"metaData":{"id":"356ae88e-8309-4ff7-ac63-d1a4b4c8055d","name":null,"description":null,"format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"entity_id\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"event_date\",\"type\":\"date\",\"nullable\":true,\"metadata\":{}},{\"name\":\"knowledge_date\",\"type\":\"timestamp\",\"nullable\":true,\"metadata\":{}},{\"name\":\"subset\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"record_id\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"actual\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"previous\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"change\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"forecast\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"unit\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"value_method\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"knowledge_time_precision\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"source_url\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"parser_version\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"ingested_at\",\"type\":\"timestamp\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":[],"createdTime":1789280104902,"configuration":{}}}
4
+ {"add":{"path":"part-00000-0c1dd060-bd5c-4fae-8a9b-156539f15191-c000.snappy.parquet","partitionValues":{},"size":4422313,"modificationTime":1789280105023,"dataChange":true,"stats":"{\"numRecords\":268960,\"minValues\":{\"subset\":\"auction_results\",\"source_url\":\"https://home.treasury.gov/resource-center/data-chart-center/inte\",\"entity_id\":\"UST_AUCTION_101D_CMB_ALLOTMENT_AT_HIGH_PCT\",\"actual\":-1.91,\"previous\":-1.91,\"value_method\":\"derived\",\"unit\":\"percent\",\"parser_version\":\"1.0.0\",\"change\":-98.69,\"knowledge_time_precision\":\"date\",\"knowledge_date\":\"1979-11-01T04:59:59Z\",\"event_date\":\"1979-10-31\",\"ingested_at\":\"2026-09-13T06:15:04.346976Z\",\"record_id\":\"UST_1979-10-31_912827KC5_RES\"},\"maxValues\":{\"change\":98.15,\"knowledge_time_precision\":\"modeled_conservative\",\"parser_version\":\"1.0.0\",\"ingested_at\":\"2026-09-13T06:15:04.346976Z\",\"unit\":\"ratio\",\"actual\":100.0,\"subset\":\"real_yield_curve\",\"event_date\":\"2026-09-11\",\"value_method\":\"reported\",\"previous\":100.0,\"knowledge_date\":\"2026-09-11T22:00:00Z\",\"record_id\":\"real_2026-09-11_7Y\",\"source_url\":\"https://www.treasurydirect.gov/xml/R_20260910_3.xml\",\"entity_id\":\"UST_REAL_LT_REAL_AVERAGE\"},\"nullCount\":{\"subset\":0,\"ingested_at\":0,\"value_method\":0,\"change\":1287,\"unit\":0,\"previous\":1287,\"forecast\":268960,\"knowledge_date\":0,\"entity_id\":0,\"knowledge_time_precision\":0,\"event_date\":0,\"source_url\":0,\"record_id\":0,\"actual\":0,\"parser_version\":0}}","tags":null,"baseRowId":null,"defaultRowCommitVersion":null,"clusteringProvider":null}}
data/pit/us_treasury_events.delta/{part-00000-c8ebf74b-2931-4d5f-a1fc-89a9f11538d2-c000.snappy.parquet → part-00000-0c1dd060-bd5c-4fae-8a9b-156539f15191-c000.snappy.parquet} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:be7416edbc85b6887e8d001e3687363c21a65e1943c587f5ec2ec6574ff66899
3
  size 4422313
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef1338f7bccf9d240965a8e1f0d4f37ddfc3648f34ead766410fd5f9808208cc
3
  size 4422313
data/real_yield_curve/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:57f535e67c879bcd3dd4e1e8dcab8b3eb5c3e247bc20d54ac460ae0f4da02a9b
3
- size 406031
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c18ab4e7dd5c33f98931270d67dc17f55d738389d14888a539d51d33b52747a
3
+ size 405625
manifest.json CHANGED
@@ -278,7 +278,7 @@
278
  "event_date": "event_date",
279
  "event_date_type": "date",
280
  "frequency_seconds": null,
281
- "generated_at": "2026-09-13T06:06:55.316266+00:00",
282
  "knowledge_date": "knowledge_date",
283
  "knowledge_date_policy": {
284
  "auction_results": "the release minute stated in the Treasury's own result artifact, from March 2008; the end of the auction day before that",
@@ -325,6 +325,6 @@
325
  "build_version": "1.0.0",
326
  "package_version": "1.0.0",
327
  "parser_version": "1.0.0",
328
- "recipe_hash": "sha256:e0be9809670e9d0159f245929daaff627d3551380944e6b2e46712d813916b16"
329
  }
330
  }
 
278
  "event_date": "event_date",
279
  "event_date_type": "date",
280
  "frequency_seconds": null,
281
+ "generated_at": "2026-09-13T06:15:05.109776+00:00",
282
  "knowledge_date": "knowledge_date",
283
  "knowledge_date_policy": {
284
  "auction_results": "the release minute stated in the Treasury's own result artifact, from March 2008; the end of the auction day before that",
 
325
  "build_version": "1.0.0",
326
  "package_version": "1.0.0",
327
  "parser_version": "1.0.0",
328
+ "recipe_hash": "sha256:77dc42e5e964da9eb90b6b30b8878e20b7155f3caa70ab25c1d39562eb2371b1"
329
  }
330
  }
metadata/build.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7ffdaae329cbacb9aa0f9cd4efbcdf85c42a044b4b48911051be875d8c744bd0
3
- size 5397
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:03c98e3c251290a58744b657c216a0e37e023bb418fe27d6f9f325131121b824
3
+ size 5399
metadata/coverage.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f905b0be74a19667b693391ec4fb95ae931a910ce690ded0ebd9cd71ba54844b
3
  size 5293
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0a15ebbad3401b780973a2a40cfd1061b4332cf0d5e278b80ecd5f88bd0ef8d
3
  size 5293
metadata/field_coverage.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:832afd0b06ac91b052a33a0d1d51c6ce0e7302f69dde664eeb8293aba08f9777
3
  size 3288
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6699652938ae0e35567dc513c3940b3d50dc09aa2b3da0ac39fd568c0e18971a
3
  size 3288
quality_report.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "ok": true,
3
- "checked_at": "2026-09-13T06:06:55.234503+00:00",
4
  "counts": {
5
  "auction_calendar": 11114,
6
  "auction_announcements": 11114,
 
1
  {
2
  "ok": true,
3
+ "checked_at": "2026-09-13T06:15:05.051922+00:00",
4
  "counts": {
5
  "auction_calendar": 11114,
6
  "auction_announcements": 11114,
recipe/pipeline.py CHANGED
@@ -58,7 +58,7 @@ from .sources.auctions import (
58
  to_float,
59
  )
60
  from .sources.curves import FEEDS, RATES_URL, parse_bill_rates, parse_curve
61
- from .store import write_table
62
  from .timing import (
63
  CURVE_TIME_BASIS,
64
  at,
@@ -127,7 +127,15 @@ def share(part: float | None, whole: float | None) -> float | None:
127
  # Auctions.
128
 
129
 
130
- async def fetch_auctions(fetcher: Fetcher) -> list[Auction]:
 
 
 
 
 
 
 
 
131
  artifact = await fetcher.get(SEARCH_URL, max_age_seconds=QUERY_MAX_AGE)
132
  auctions = parse_auctions(json.loads(artifact.text))
133
  # The announced feed is the same shape and holds auctions that the search
@@ -140,7 +148,7 @@ async def fetch_auctions(fetcher: Fetcher) -> list[Auction]:
140
  if auction.auction_id not in held:
141
  auctions.append(auction)
142
  auctions.sort(key=lambda auction: (auction.auction_date, auction.row.get("cusip") or ""))
143
- return auctions
144
 
145
 
146
  async def result_times(fetcher: Fetcher, auction: Auction) -> tuple[Artifact | None, dict]:
@@ -451,8 +459,38 @@ def curve_features(nominal: pl.DataFrame, real: pl.DataFrame) -> pl.DataFrame:
451
  # The run.
452
 
453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
  async def build(
455
- *, settings: Settings, limit: int | None = None, refresh: bool = False
 
 
 
 
456
  ) -> tuple[dict[str, pl.DataFrame], list[Quarantined]]:
457
  user_agent = validate_user_agent(settings.user_agent)
458
  quarantined: list[Quarantined] = []
@@ -466,14 +504,34 @@ async def build(
466
  requests_per_second=settings.requests_per_second,
467
  force_revalidate=refresh,
468
  ) as fetcher:
469
- auctions = await fetch_auctions(fetcher)
470
  if limit:
471
  auctions = auctions[-limit:]
472
- LOGGER.info("%d auctions in the query", len(auctions))
 
 
 
 
473
  for index, auction in enumerate(auctions, start=1):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  artifact, times = await result_times(fetcher, auction)
475
- calendar.append(calendar_row(auction, artifact=artifact, times=times))
476
- announcement = announcement_row(auction, artifact=artifact, times=times)
477
  if announcement is not None:
478
  announcements.append(announcement)
479
  result = result_row(auction, artifact=artifact, times=times)
@@ -485,6 +543,7 @@ async def build(
485
  )
486
  if index % 1000 == 0:
487
  LOGGER.info("%d/%d auctions read", index, len(auctions))
 
488
 
489
  curves = await fetch_curves(fetcher, first_year=settings.first_curve_year)
490
 
@@ -530,7 +589,9 @@ def run_build(
530
  ) -> BuildResult:
531
  import shutil
532
 
533
- frames, quarantined = asyncio.run(build(settings=settings, limit=limit, refresh=rebuild))
 
 
534
  data_dir = Path(settings.data_dir)
535
  counts = {name: write_table(data_dir, name, frame) for name, frame in frames.items()}
536
 
@@ -579,6 +640,7 @@ __all__ = [
579
  "calendar_row",
580
  "curve_features",
581
  "curve_rows",
 
582
  "result_row",
583
  "run_build",
584
  "share",
 
58
  to_float,
59
  )
60
  from .sources.curves import FEEDS, RATES_URL, parse_bill_rates, parse_curve
61
+ from .store import read_table, write_table
62
  from .timing import (
63
  CURVE_TIME_BASIS,
64
  at,
 
127
  # Auctions.
128
 
129
 
130
+ async def fetch_auctions(fetcher: Fetcher) -> tuple[list[Auction], Artifact]:
131
+ """Every security in the query, and the query document they came from.
132
+
133
+ The document is returned with them because the calendar and announcement
134
+ rows are built from it and nothing else. An earlier version attached the
135
+ digest of the result artifact to those rows, which is the digest of a
136
+ different document saying different things.
137
+ """
138
+
139
  artifact = await fetcher.get(SEARCH_URL, max_age_seconds=QUERY_MAX_AGE)
140
  auctions = parse_auctions(json.loads(artifact.text))
141
  # The announced feed is the same shape and holds auctions that the search
 
148
  if auction.auction_id not in held:
149
  auctions.append(auction)
150
  auctions.sort(key=lambda auction: (auction.auction_date, auction.row.get("cusip") or ""))
151
+ return auctions, artifact
152
 
153
 
154
  async def result_times(fetcher: Fetcher, auction: Auction) -> tuple[Artifact | None, dict]:
 
459
  # The run.
460
 
461
 
462
+ def held_results(data_dir: Path) -> dict[str, dict]:
463
+ """The result rows a previous run already published, by auction.
464
+
465
+ A finished auction's result artifact never changes, so a run that already
466
+ has the row does not need to ask TreasuryDirect for it again. Without this
467
+ every scheduled run would refetch six thousand artifacts -- forty minutes
468
+ of somebody else's bandwidth to rediscover numbers that cannot move.
469
+
470
+ Only rows whose instant came from an artifact are reused. A row dated to
471
+ the end of its day is one whose artifact was never found, and the next run
472
+ should look again in case the Treasury has since published one.
473
+ """
474
+
475
+ try:
476
+ rows = read_table(data_dir, "auction_results").collect()
477
+ except (FileNotFoundError, pl.exceptions.ComputeError):
478
+ return {}
479
+ if rows.is_empty():
480
+ return {}
481
+ return {
482
+ row["auction_id"]: row
483
+ for row in rows.iter_rows(named=True)
484
+ if row["knowledge_time_precision"] == "minute"
485
+ }
486
+
487
+
488
  async def build(
489
+ *,
490
+ settings: Settings,
491
+ limit: int | None = None,
492
+ refresh: bool = False,
493
+ reuse: bool = True,
494
  ) -> tuple[dict[str, pl.DataFrame], list[Quarantined]]:
495
  user_agent = validate_user_agent(settings.user_agent)
496
  quarantined: list[Quarantined] = []
 
504
  requests_per_second=settings.requests_per_second,
505
  force_revalidate=refresh,
506
  ) as fetcher:
507
+ auctions, query = await fetch_auctions(fetcher)
508
  if limit:
509
  auctions = auctions[-limit:]
510
+ held = held_results(Path(settings.data_dir)) if reuse and not refresh else {}
511
+ LOGGER.info(
512
+ "%d auctions in the query, %d results already held", len(auctions), len(held)
513
+ )
514
+ reused = 0
515
  for index, auction in enumerate(auctions, start=1):
516
+ known = held.get(auction.auction_id)
517
+ if known is not None:
518
+ # The artifact was read on an earlier run and cannot have
519
+ # changed. Its closing times come from the query, which has
520
+ # them too.
521
+ times = {
522
+ "competitive_close": auction.row.get("closingTimeCompetitive"),
523
+ "noncompetitive_close": auction.row.get("closingTimeNoncompetitive"),
524
+ }
525
+ calendar.append(calendar_row(auction, artifact=query, times=times))
526
+ announcement = announcement_row(auction, artifact=query, times=times)
527
+ if announcement is not None:
528
+ announcements.append(announcement)
529
+ results.append(known)
530
+ reused += 1
531
+ continue
532
  artifact, times = await result_times(fetcher, auction)
533
+ calendar.append(calendar_row(auction, artifact=query, times=times))
534
+ announcement = announcement_row(auction, artifact=query, times=times)
535
  if announcement is not None:
536
  announcements.append(announcement)
537
  result = result_row(auction, artifact=artifact, times=times)
 
543
  )
544
  if index % 1000 == 0:
545
  LOGGER.info("%d/%d auctions read", index, len(auctions))
546
+ LOGGER.info("%d results reused, %d read from source", reused, len(results) - reused)
547
 
548
  curves = await fetch_curves(fetcher, first_year=settings.first_curve_year)
549
 
 
589
  ) -> BuildResult:
590
  import shutil
591
 
592
+ frames, quarantined = asyncio.run(
593
+ build(settings=settings, limit=limit, refresh=rebuild, reuse=not rebuild)
594
+ )
595
  data_dir = Path(settings.data_dir)
596
  counts = {name: write_table(data_dir, name, frame) for name, frame in frames.items()}
597
 
 
640
  "calendar_row",
641
  "curve_features",
642
  "curve_rows",
643
+ "held_results",
644
  "result_row",
645
  "run_build",
646
  "share",
tests/test_auctions.py CHANGED
@@ -160,3 +160,33 @@ def test_derived_shares_use_only_numbers_from_the_same_result(auction_rows):
160
  def test_an_auction_with_no_date_is_not_an_auction():
161
  assert parse_auctions([{"cusip": "X", "auctionDate": ""}]) == []
162
  assert isinstance(Auction(auction_id="x", row={}), Auction)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  def test_an_auction_with_no_date_is_not_an_auction():
161
  assert parse_auctions([{"cusip": "X", "auctionDate": ""}]) == []
162
  assert isinstance(Auction(auction_id="x", row={}), Auction)
163
+
164
+
165
+ def test_only_results_dated_from_an_artifact_are_reused(tmp_path):
166
+ """A finished auction's artifact cannot change; a missing one might appear.
167
+
168
+ Reusing a row that was dated to the end of its day would mean never looking
169
+ again for an artifact the Treasury had since published.
170
+ """
171
+
172
+ import polars as pl
173
+
174
+ from recipe.pipeline import held_results
175
+ from recipe.schema import RESULT_SCHEMA, align
176
+ from recipe.store import write_table
177
+
178
+ rows = [
179
+ {"result_id": "A", "auction_id": "UST_2020-01-02_X", "knowledge_time_precision": "minute"},
180
+ {"result_id": "B", "auction_id": "UST_1998-07-27_Y", "knowledge_time_precision": "date"},
181
+ ]
182
+ data_dir = tmp_path / "data"
183
+ write_table(data_dir, "auction_results",
184
+ align(pl.DataFrame(rows, infer_schema_length=None), RESULT_SCHEMA))
185
+ held = held_results(data_dir)
186
+ assert set(held) == {"UST_2020-01-02_X"}
187
+
188
+
189
+ def test_nothing_is_held_when_there_is_no_published_tree(tmp_path):
190
+ from recipe.pipeline import held_results
191
+
192
+ assert held_results(tmp_path / "nothing") == {}