ZipLime commited on
Commit
d2ec17d
·
verified ·
1 Parent(s): df0c028

Update the FOMC events dataset

Browse files
PIPELINE.md CHANGED
@@ -221,15 +221,29 @@ change, so a run that already holds the row does not ask TreasuryDirect for it
221
  again: the first build reads 6 229 artifacts in about thirty-five minutes, and
222
  every run after it reuses them and finishes in **four seconds**.
223
 
224
- Only rows whose instant came from an artifact are reused. A row dated to the
225
- end of its day is one whose artifact was never found, and the next run looks
226
- again in case the Treasury has since published one. The rate feeds are reused
227
- by whole year, and never the current one. `--rebuild` ignores held rows
228
- entirely, which is what a parser change needs.
229
-
230
- Between them, the two reuse paths take a run that fetched 12 832 documents down
231
- to **seven requests** and about **three seconds**, producing byte-identical
232
- tables.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
 
234
  ## Scheduling
235
 
 
221
  again: the first build reads 6 229 artifacts in about thirty-five minutes, and
222
  every run after it reuses them and finishes in **four seconds**.
223
 
224
+ What decides reuse for an auction is `raw_sha256`, not the precision of its
225
+ instant. A row carrying a digest is one whose artifact was fetched and read,
226
+ and that is settled whether or not the artifact turned out to state a release
227
+ time -- **1 357 of them do not**, and reusing only the `minute` rows meant
228
+ refetching every one of those on every run, forever, looking for a line that
229
+ was never going to appear. A row with no digest is one whose artifact was never
230
+ found, and that one is worth looking for again.
231
+
232
+ For the rate feeds, **every** past year is settled, not only the ones that
233
+ produced rows. The real curve begins in 2003 and the years before it return a
234
+ file with nothing but a header; holding only the years with data meant fetching
235
+ thirteen empty years on every run to be told again that they are empty.
236
+
237
+ Five auctions of 11 114 state a noncompetitive closing time in the artifact
238
+ that the query leaves empty, so those two fields are carried forward from the
239
+ held announcement rather than rebuilt from the query. Without that the
240
+ incremental build would quietly drop a field the dataset already had.
241
+
242
+ Between them the reuse paths take a run that fetched 12 832 documents down to
243
+ **seven requests** and about **two and a half seconds**, and the tables it
244
+ produces are identical to the full build's in all eight configs.
245
+
246
+ `--rebuild` ignores held rows entirely, which is what a parser change needs.
247
 
248
  ## Scheduling
249
 
data/auction_announcements/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:692a186e39738bc86fc3b8af18636588db19d5913078fcf7bb0d688ae829f639
3
- size 484959
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7e6cbb7ac9ef1e08b451fc205789b587a211cfacc6ae1fd688e7699f28f26d5
3
+ size 479469
data/auction_calendar/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fb441c1e6dc9a94a129f12ffa42d49af122fcd8f100b59f237f5e44fa12cbf6d
3
- size 423326
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f7e6d146262f9d5c07231213be3c1210956ae538d32d2f54f3ba7d75abfa810
3
+ size 417766
data/auction_results/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f5b44ea9b34f5e17eb57ce07f91fc145e5a05fcf8946c6644e69140648ce9d68
3
- size 1622007
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:26a7eaac97521473015ead61d5b1d0994eeb376c7d73e511970b3cdee49721a4
3
+ size 1618329
data/bill_rates/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c064c75cb56860cd1ed0079288433a2bb4d04b974caa7063c5f49fff2caedb5e
3
- size 367317
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a4fca2ba6f4c3c23769fb7f74f3897875f068ac951166bb215d5c5a3144d0b5
3
+ size 368155
data/curve_features/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0d770c3a9de413c0254eae39e571baf343f2e496e9cf0531d8b397a4d4f307cb
3
  size 189724
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d3f4c480ed4beb53570b75ac55b9fb353f9fcb63749c85d5051cd1552a0bad8
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:9a936baed49df2ea2fc8f817ef40cc4c3298159885fd818ee51bb6029fea916f
3
- size 716156
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d3add81c0817d90cbe5d9e97d77cc7326fe79b8203395cbd4df31618ebfe28d7
3
+ size 716704
data/pit/part-00000.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:cc259aa2cd92eaba61469855685332dec9b7dfe273784080a2f0431eaeac4a31
3
- size 2717527
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2948d11c2fc9a90792fbfa22d3d0a33f4ff4b98bf2aaa5a9dbcfe63ca5736eb1
3
+ size 2724267
data/pit/us_treasury_events.delta/_delta_log/00000000000000000000.json CHANGED
@@ -1,4 +1,4 @@
1
- {"commitInfo":{"timestamp":1789281137938,"operation":"WRITE","operationParameters":{"mode":"Overwrite"},"engineInfo":"delta-rs:py-1.6.3","operationMetrics":{"num_added_files":1,"num_removed_files":0,"num_partitions":0,"num_added_rows":268960,"execution_time_ms":154},"clientVersion":"delta-rs.py-1.6.3"}}
2
  {"protocol":{"minReaderVersion":1,"minWriterVersion":2}}
3
- {"metaData":{"id":"b4b79ff4-fa82-4a52-a5c7-969fe63f41bf","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":1789281137783,"configuration":{}}}
4
- {"add":{"path":"part-00000-2bb0a7ee-ab33-41bf-9c32-fe0953ae83dd-c000.snappy.parquet","partitionValues":{},"size":4421397,"modificationTime":1789281137938,"dataChange":true,"stats":"{\"numRecords\":268960,\"minValues\":{\"subset\":\"auction_results\",\"value_method\":\"derived\",\"event_date\":\"1979-10-31\",\"unit\":\"percent\",\"change\":-98.69,\"knowledge_date\":\"1979-11-01T04:59:59Z\",\"knowledge_time_precision\":\"date\",\"record_id\":\"UST_1979-10-31_912827KC5_RES\",\"actual\":-1.91,\"previous\":-1.91,\"entity_id\":\"UST_AUCTION_101D_CMB_ALLOTMENT_AT_HIGH_PCT\",\"source_url\":\"https://home.treasury.gov/resource-center/data-chart-center/inte\",\"parser_version\":\"1.0.0\",\"ingested_at\":\"2026-09-13T06:32:16.488770Z\"},\"maxValues\":{\"ingested_at\":\"2026-09-13T06:32:16.488770Z\",\"subset\":\"real_yield_curve\",\"value_method\":\"reported\",\"unit\":\"ratio\",\"entity_id\":\"UST_REAL_LT_REAL_AVERAGE\",\"actual\":100.0,\"record_id\":\"real_2026-09-11_7Y\",\"knowledge_time_precision\":\"modeled_conservative\",\"knowledge_date\":\"2026-09-11T22:00:00Z\",\"event_date\":\"2026-09-11\",\"previous\":100.0,\"parser_version\":\"1.0.0\",\"source_url\":\"https://www.treasurydirect.gov/xml/R_20260910_3.xml\",\"change\":98.15},\"nullCount\":{\"source_url\":0,\"entity_id\":0,\"record_id\":0,\"value_method\":0,\"event_date\":0,\"parser_version\":0,\"ingested_at\":0,\"forecast\":268960,\"subset\":0,\"actual\":0,\"knowledge_date\":0,\"knowledge_time_precision\":0,\"previous\":1287,\"unit\":0,\"change\":1287}}","tags":null,"baseRowId":null,"defaultRowCommitVersion":null,"clusteringProvider":null}}
 
1
+ {"commitInfo":{"timestamp":1789281131033,"operation":"WRITE","operationParameters":{"mode":"Overwrite"},"engineInfo":"delta-rs:py-1.6.2","operationMetrics":{"execution_time_ms":178,"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":"f3316422-d5b5-4edf-a62e-452af79dbd56","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":1789281130859,"configuration":{}}}
4
+ {"add":{"path":"part-00000-b2b0b029-9fa3-4076-932c-17ffc313e68b-c000.snappy.parquet","partitionValues":{},"size":4422313,"modificationTime":1789281131031,"dataChange":true,"stats":"{\"numRecords\":268960,\"minValues\":{\"unit\":\"percent\",\"subset\":\"auction_results\",\"event_date\":\"1979-10-31\",\"knowledge_date\":\"1979-11-01T04:59:59Z\",\"change\":-98.69,\"value_method\":\"derived\",\"record_id\":\"UST_1979-10-31_912827KC5_RES\",\"source_url\":\"https://home.treasury.gov/resource-center/data-chart-center/inte\",\"knowledge_time_precision\":\"date\",\"actual\":-1.91,\"parser_version\":\"1.0.0\",\"ingested_at\":\"2026-09-13T06:32:10.260494Z\",\"previous\":-1.91,\"entity_id\":\"UST_AUCTION_101D_CMB_ALLOTMENT_AT_HIGH_PCT\"},\"maxValues\":{\"unit\":\"ratio\",\"parser_version\":\"1.0.0\",\"entity_id\":\"UST_REAL_LT_REAL_AVERAGE\",\"subset\":\"real_yield_curve\",\"record_id\":\"real_2026-09-11_7Y\",\"previous\":100.0,\"knowledge_time_precision\":\"modeled_conservative\",\"knowledge_date\":\"2026-09-11T22:00:00Z\",\"value_method\":\"reported\",\"actual\":100.0,\"change\":98.15,\"ingested_at\":\"2026-09-13T06:32:10.260494Z\",\"source_url\":\"https://www.treasurydirect.gov/xml/R_20260910_3.xml\",\"event_date\":\"2026-09-11\"},\"nullCount\":{\"entity_id\":0,\"knowledge_date\":0,\"value_method\":0,\"unit\":0,\"ingested_at\":0,\"previous\":1287,\"forecast\":268960,\"parser_version\":0,\"event_date\":0,\"subset\":0,\"actual\":0,\"change\":1287,\"knowledge_time_precision\":0,\"record_id\":0,\"source_url\":0}}","tags":null,"baseRowId":null,"defaultRowCommitVersion":null,"clusteringProvider":null}}
data/pit/us_treasury_events.delta/{part-00000-2bb0a7ee-ab33-41bf-9c32-fe0953ae83dd-c000.snappy.parquet → part-00000-b2b0b029-9fa3-4076-932c-17ffc313e68b-c000.snappy.parquet} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2fd230b729a22d09c271aa25659ed5089d8a4a9c0b86adf9f670243cf3825f3c
3
- size 4421397
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0622c8b9a7af158cf88ebca5c9c5c961d30ef4c4010cd67fc53ac1f06143fdf9
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:7a8e2dba4f8faa9305d0889cb1a79a522350c5eb45669424223bc57cce415336
3
- size 404917
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:574beeb24aa0a7952d8e92960e8ad9296aea153b1f0c37f1622fd932ad95e664
3
+ size 405997
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:32:18.135320+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:60df5049dcd4040bdb200538634016989252ecf3b34869851220140908e55608"
329
  }
330
  }
 
278
  "event_date": "event_date",
279
  "event_date_type": "date",
280
  "frequency_seconds": null,
281
+ "generated_at": "2026-09-13T06:32:11.129328+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:2807f605f7c9b8a56e579329be5a28fc38539806641e82030a079a47db686251"
329
  }
330
  }
metadata/build.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:65b64053deb2eaab79fa9b57d43f7654bd2b06c09143ce999a26f39ebf48ddd3
3
- size 4221
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:687437599d62c0354dd6e0c60bf35873431cdfdaa9ef8a5e28a95e0a23eec6a2
3
+ size 5400
metadata/coverage.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:205f248a45dbebb9c7080d6ce6aaecdaf31e36f551603e788d32ec4f912dfcd9
3
- size 4481
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ec7f64315ba94eadf641deefff9edc8cc6d9976847a0968fca35a3fc9d24b92
3
+ size 5293
metadata/field_coverage.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:801f6bc84e6261ed0df3fad147b5155560db2469904d4b611fef0445937d3634
3
  size 3288
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fcdd257538b3ab9b7b50e10926538138ba3d43e8389b0ecb86abf83b2754486f
3
  size 3288
metadata/yield_curve_methodology.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:882bffde7a4e2b4fde94cc44888ae9b4b828527dec37378fcf990c5cd99ede31
3
- size 3984
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d6f5f4f319e27c751f43091c907c3055e12a58da5a737449ceb646a75fd7462
3
+ size 7308
quality_report.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "ok": true,
3
- "checked_at": "2026-09-13T06:32:17.960289+00:00",
4
  "counts": {
5
  "auction_calendar": 11114,
6
  "auction_announcements": 11114,
 
1
  {
2
  "ok": true,
3
+ "checked_at": "2026-09-13T06:32:11.067792+00:00",
4
  "counts": {
5
  "auction_calendar": 11114,
6
  "auction_announcements": 11114,
recipe/pipeline.py CHANGED
@@ -30,7 +30,7 @@ from pathlib import Path
30
 
31
  import polars as pl
32
 
33
- from .config import COUNTRY, Settings, validate_user_agent
34
  from .coverage import write_build_record, write_coverage
35
  from .http import Artifact, Fetcher
36
  from .methodology import methodology_for, write_registry
@@ -332,7 +332,32 @@ def result_row(auction: Auction, *, artifact: Artifact | None, times: dict) -> d
332
  CURVE_CONCURRENCY = 6
333
 
334
 
335
- def held_curve_years(data_dir: Path) -> dict[str, set[int]]:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  """Which years of which feed a previous run already published.
337
 
338
  A year of rates that is over cannot change, and each of these files is
@@ -345,7 +370,7 @@ def held_curve_years(data_dir: Path) -> dict[str, set[int]]:
345
 
346
  this_year = datetime.now(UTC).year
347
  held: dict[str, set[int]] = {}
348
- for feed, (table, curve_type, column) in FEED_TABLES.items():
349
  try:
350
  rows = read_table(data_dir, table).collect()
351
  except (FileNotFoundError, pl.exceptions.ComputeError):
@@ -354,8 +379,14 @@ def held_curve_years(data_dir: Path) -> dict[str, set[int]]:
354
  continue
355
  if curve_type is not None:
356
  rows = rows.filter(pl.col("curve_type") == curve_type)
357
- years = set(rows[column].dt.year().unique().to_list())
358
- held[feed] = {year for year in years if year < this_year}
 
 
 
 
 
 
359
  return held
360
 
361
 
@@ -531,9 +562,14 @@ def held_results(data_dir: Path) -> dict[str, dict]:
531
  every scheduled run would refetch six thousand artifacts -- forty minutes
532
  of somebody else's bandwidth to rediscover numbers that cannot move.
533
 
534
- Only rows whose instant came from an artifact are reused. A row dated to
535
- the end of its day is one whose artifact was never found, and the next run
536
- should look again in case the Treasury has since published one.
 
 
 
 
 
537
  """
538
 
539
  try:
@@ -545,7 +581,7 @@ def held_results(data_dir: Path) -> dict[str, dict]:
545
  return {
546
  row["auction_id"]: row
547
  for row in rows.iter_rows(named=True)
548
- if row["knowledge_time_precision"] == "minute"
549
  }
550
 
551
 
@@ -572,6 +608,7 @@ async def build(
572
  if limit:
573
  auctions = auctions[-limit:]
574
  held = held_results(Path(settings.data_dir)) if reuse and not refresh else {}
 
575
  LOGGER.info(
576
  "%d auctions in the query, %d results already held", len(auctions), len(held)
577
  )
@@ -589,6 +626,11 @@ async def build(
589
  calendar.append(calendar_row(auction, artifact=query, times=times))
590
  announcement = announcement_row(auction, artifact=query, times=times)
591
  if announcement is not None:
 
 
 
 
 
592
  announcements.append(announcement)
593
  results.append(known)
594
  reused += 1
@@ -609,7 +651,11 @@ async def build(
609
  LOGGER.info("%d/%d auctions read", index, len(auctions))
610
  LOGGER.info("%d results reused, %d read from source", reused, len(results) - reused)
611
 
612
- held_years = held_curve_years(Path(settings.data_dir)) if reuse and not refresh else {}
 
 
 
 
613
  curves = await fetch_curves(
614
  fetcher, first_year=settings.first_curve_year, skip=held_years
615
  )
@@ -722,6 +768,7 @@ __all__ = [
722
  "calendar_row",
723
  "curve_features",
724
  "curve_rows",
 
725
  "held_curve_rows",
726
  "held_curve_years",
727
  "held_results",
 
30
 
31
  import polars as pl
32
 
33
+ from .config import COUNTRY, FIRST_CURVE_YEAR, Settings, validate_user_agent
34
  from .coverage import write_build_record, write_coverage
35
  from .http import Artifact, Fetcher
36
  from .methodology import methodology_for, write_registry
 
332
  CURVE_CONCURRENCY = 6
333
 
334
 
335
+ def held_closing_times(data_dir: Path) -> dict[str, dict]:
336
+ """The closing times a previous run read out of an artifact.
337
+
338
+ Almost every auction has its closing times in the query as well, but five
339
+ of 11 114 do not: the artifact states a noncompetitive close that the query
340
+ leaves empty. Rebuilding those announcements from the query alone would
341
+ quietly drop a field that the dataset already had, and the incremental
342
+ build would stop matching the full one.
343
+ """
344
+
345
+ try:
346
+ rows = read_table(data_dir, "auction_announcements").collect()
347
+ except (FileNotFoundError, pl.exceptions.ComputeError):
348
+ return {}
349
+ if rows.is_empty():
350
+ return {}
351
+ return {
352
+ row["auction_id"]: {
353
+ "competitive_close_at": row["competitive_close_at"],
354
+ "noncompetitive_close_at": row["noncompetitive_close_at"],
355
+ }
356
+ for row in rows.iter_rows(named=True)
357
+ }
358
+
359
+
360
+ def held_curve_years(data_dir: Path, *, first_year: int = FIRST_CURVE_YEAR) -> dict[str, set[int]]:
361
  """Which years of which feed a previous run already published.
362
 
363
  A year of rates that is over cannot change, and each of these files is
 
370
 
371
  this_year = datetime.now(UTC).year
372
  held: dict[str, set[int]] = {}
373
+ for feed, (table, curve_type, _column) in FEED_TABLES.items():
374
  try:
375
  rows = read_table(data_dir, table).collect()
376
  except (FileNotFoundError, pl.exceptions.ComputeError):
 
379
  continue
380
  if curve_type is not None:
381
  rows = rows.filter(pl.col("curve_type") == curve_type)
382
+ if rows.is_empty():
383
+ continue
384
+ # Every past year is settled, not only the ones that produced rows.
385
+ # The real curve starts in 2003 and the years before it return a file
386
+ # with nothing but a header; treating those as unread meant fetching
387
+ # thirteen empty years on every run, forever, to be told again that
388
+ # they are empty.
389
+ held[feed] = set(range(first_year, this_year))
390
  return held
391
 
392
 
 
562
  every scheduled run would refetch six thousand artifacts -- forty minutes
563
  of somebody else's bandwidth to rediscover numbers that cannot move.
564
 
565
+ What decides reuse is `raw_sha256`, not the precision. A row carrying a
566
+ digest is one whose artifact was fetched and read, and that is settled
567
+ whether or not the artifact turned out to state a release time -- 1 357 of
568
+ them do not, and an earlier version of this function kept refetching every
569
+ one of them forever, looking for a line that was never going to appear.
570
+
571
+ A row with no digest is one whose artifact was never found. Those are
572
+ looked for again, in case the Treasury has since published one.
573
  """
574
 
575
  try:
 
581
  return {
582
  row["auction_id"]: row
583
  for row in rows.iter_rows(named=True)
584
+ if row["raw_sha256"]
585
  }
586
 
587
 
 
608
  if limit:
609
  auctions = auctions[-limit:]
610
  held = held_results(Path(settings.data_dir)) if reuse and not refresh else {}
611
+ held_times = held_closing_times(Path(settings.data_dir)) if held else {}
612
  LOGGER.info(
613
  "%d auctions in the query, %d results already held", len(auctions), len(held)
614
  )
 
626
  calendar.append(calendar_row(auction, artifact=query, times=times))
627
  announcement = announcement_row(auction, artifact=query, times=times)
628
  if announcement is not None:
629
+ # Carry forward the two fields that came from the artifact
630
+ # and are not in the query.
631
+ for field, value in (held_times.get(auction.auction_id) or {}).items():
632
+ if announcement.get(field) is None:
633
+ announcement[field] = value
634
  announcements.append(announcement)
635
  results.append(known)
636
  reused += 1
 
651
  LOGGER.info("%d/%d auctions read", index, len(auctions))
652
  LOGGER.info("%d results reused, %d read from source", reused, len(results) - reused)
653
 
654
+ held_years = (
655
+ held_curve_years(Path(settings.data_dir), first_year=settings.first_curve_year)
656
+ if reuse and not refresh
657
+ else {}
658
+ )
659
  curves = await fetch_curves(
660
  fetcher, first_year=settings.first_curve_year, skip=held_years
661
  )
 
768
  "calendar_row",
769
  "curve_features",
770
  "curve_rows",
771
+ "held_closing_times",
772
  "held_curve_rows",
773
  "held_curve_years",
774
  "held_results",
tests/test_auctions.py CHANGED
@@ -162,11 +162,14 @@ def test_an_auction_with_no_date_is_not_an_auction():
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
@@ -176,17 +179,55 @@ def test_only_results_dated_from_an_artifact_are_reused(tmp_path):
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") == {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  assert isinstance(Auction(auction_id="x", row={}), Auction)
163
 
164
 
165
+ def test_a_row_is_reused_when_its_artifact_was_read(tmp_path):
166
+ """The digest decides, not the precision.
167
+
168
+ 1 357 artifacts exist and state no release time. Their rows are dated to
169
+ the end of the auction day, and an earlier version of this rule refetched
170
+ every one of them on every run, looking for a line that was never going to
171
+ appear. A row with no digest is one whose artifact was never found, and
172
+ that one is worth looking for again.
173
  """
174
 
175
  import polars as pl
 
179
  from recipe.store import write_table
180
 
181
  rows = [
182
+ # Artifact read, stated a release minute.
183
+ {"result_id": "A", "auction_id": "UST_2020-01-02_X",
184
+ "knowledge_time_precision": "minute", "raw_sha256": "aaa"},
185
+ # Artifact read, stated no release time. Settled all the same.
186
+ {"result_id": "B", "auction_id": "UST_2009-03-05_Y",
187
+ "knowledge_time_precision": "date", "raw_sha256": "bbb"},
188
+ # No artifact was ever found. Look again.
189
+ {"result_id": "C", "auction_id": "UST_1998-07-27_Z",
190
+ "knowledge_time_precision": "date", "raw_sha256": None},
191
  ]
192
  data_dir = tmp_path / "data"
193
  write_table(data_dir, "auction_results",
194
  align(pl.DataFrame(rows, infer_schema_length=None), RESULT_SCHEMA))
195
  held = held_results(data_dir)
196
+ assert set(held) == {"UST_2020-01-02_X", "UST_2009-03-05_Y"}
197
 
198
 
199
  def test_nothing_is_held_when_there_is_no_published_tree(tmp_path):
200
  from recipe.pipeline import held_results
201
 
202
  assert held_results(tmp_path / "nothing") == {}
203
+
204
+
205
+ def test_closing_times_that_only_the_artifact_had_survive_a_reuse(tmp_path):
206
+ """Five auctions of 11 114 state a noncompetitive close only in the artifact.
207
+
208
+ Rebuilding their announcement from the query alone would silently drop a
209
+ field the dataset already had, and the incremental build would stop
210
+ matching the full one.
211
+ """
212
+
213
+ import polars as pl
214
+
215
+ from recipe.pipeline import held_closing_times
216
+ from recipe.schema import ANNOUNCEMENT_SCHEMA, align
217
+ from recipe.store import write_table
218
+
219
+ rows = [
220
+ {
221
+ "announcement_id": "UST_2020-07-13_X_ANN",
222
+ "auction_id": "UST_2020-07-13_X",
223
+ "competitive_close_at": datetime(2020, 7, 13, 15, 30, tzinfo=UTC),
224
+ "noncompetitive_close_at": datetime(2020, 7, 10, 15, 0, tzinfo=UTC),
225
+ }
226
+ ]
227
+ data_dir = tmp_path / "data"
228
+ write_table(data_dir, "auction_announcements",
229
+ align(pl.DataFrame(rows, infer_schema_length=None), ANNOUNCEMENT_SCHEMA))
230
+ held = held_closing_times(data_dir)
231
+ assert held["UST_2020-07-13_X"]["noncompetitive_close_at"] == datetime(
232
+ 2020, 7, 10, 15, 0, tzinfo=UTC
233
+ )
tests/test_curves.py CHANGED
@@ -112,8 +112,14 @@ def test_the_methodology_changed_on_the_date_the_treasury_states():
112
  assert all(len(text) > 100 for text in table["description"])
113
 
114
 
115
- def test_only_finished_years_of_a_feed_are_reused(tmp_path):
116
- """A year that is over cannot change. The current year gains a row a day."""
 
 
 
 
 
 
117
 
118
  from datetime import UTC, datetime
119
 
@@ -127,13 +133,13 @@ def test_only_finished_years_of_a_feed_are_reused(tmp_path):
127
  rows = [
128
  {"curve_id": f"nominal_{year}-06-01_10Y", "curve_date": date(year, 6, 1),
129
  "curve_type": "nominal", "maturity": "10Y", "yield_pct": 4.0}
130
- for year in (this_year - 2, this_year - 1, this_year)
131
  ]
132
  data_dir = tmp_path / "data"
133
  write_table(data_dir, "nominal_yield_curve",
134
  align(pl.DataFrame(rows, infer_schema_length=None), CURVE_SCHEMA))
135
- held = held_curve_years(data_dir)
136
- assert held["nominal"] == {this_year - 2, this_year - 1}
137
  assert this_year not in held["nominal"]
138
 
139
 
@@ -155,9 +161,12 @@ def test_two_feeds_sharing_a_table_are_tracked_apart(tmp_path):
155
  data_dir = tmp_path / "data"
156
  write_table(data_dir, "nominal_yield_curve",
157
  align(pl.DataFrame(rows, infer_schema_length=None), CURVE_SCHEMA))
158
- held = held_curve_years(data_dir)
159
- assert held["nominal"] == {2010}
160
- assert held["long_term_composite"] == {2011}
 
 
 
161
 
162
 
163
  def test_nothing_is_held_without_a_published_tree(tmp_path):
 
112
  assert all(len(text) > 100 for text in table["description"])
113
 
114
 
115
+ def test_every_past_year_is_settled_including_the_empty_ones(tmp_path):
116
+ """A past year with no rows is a year the Treasury published nothing for.
117
+
118
+ The real curve begins in 2003 and the years before it return a file with
119
+ nothing but a header. Holding only the years that produced rows meant
120
+ refetching those empty years on every run, forever, to be told again that
121
+ they are empty. The current year is never held: it gains a row a day.
122
+ """
123
 
124
  from datetime import UTC, datetime
125
 
 
133
  rows = [
134
  {"curve_id": f"nominal_{year}-06-01_10Y", "curve_date": date(year, 6, 1),
135
  "curve_type": "nominal", "maturity": "10Y", "yield_pct": 4.0}
136
+ for year in (this_year - 2, this_year)
137
  ]
138
  data_dir = tmp_path / "data"
139
  write_table(data_dir, "nominal_yield_curve",
140
  align(pl.DataFrame(rows, infer_schema_length=None), CURVE_SCHEMA))
141
+ held = held_curve_years(data_dir, first_year=this_year - 5)
142
+ assert held["nominal"] == set(range(this_year - 5, this_year))
143
  assert this_year not in held["nominal"]
144
 
145
 
 
161
  data_dir = tmp_path / "data"
162
  write_table(data_dir, "nominal_yield_curve",
163
  align(pl.DataFrame(rows, infer_schema_length=None), CURVE_SCHEMA))
164
+ held = held_curve_years(data_dir, first_year=2010)
165
+ # Both feeds have published rows, so both hold every past year.
166
+ assert 2010 in held["nominal"]
167
+ assert 2011 in held["long_term_composite"]
168
+ # A feed with no rows at all holds nothing.
169
+ assert "real" not in held
170
 
171
 
172
  def test_nothing_is_held_without_a_published_tree(tmp_path):