#!/usr/bin/env python3 """Publish the WARN COVERAGE SURVEY — "which US states publish WARN Act layoff notices, which publish none, and how deep each public archive goes" — as its own Hugging Face dataset. (c342, 2026-09-12.) WHY THIS EXISTS — evidence, not a hunch: * c341 found that Arkansas, New Hampshire and Wyoming publish NO public WARN list at all (searched 2026-09-13; PR/GU/VI run no portal). So "48 states" is complete coverage of what is publishable, and the survey itself is the artifact a data buyer wants. It shipped on our site as coverage.html. * c339/c335 measured: OUR host (`*.hf.space`) does not rank on Google; `huggingface.co` dataset cards do (we are result #1 for the core buyer query, and every ranking URL is a card). c342 measured three coverage queries ("which states publish WARN notices list", "does Arkansas publish WARN notices", "how far back does California WARN data go"): our coverage.html is absent from all three; layoffalert.org/states and layoffdata.com's blog own them. A card is the surface that can rank. * Checked on the Hub 2026-09-12 BEFORE publishing: `warn coverage` and `warn states` each returned ZERO datasets hub-wide. Hub search is substring-per-token on the repo id (c334), so the id carries the words a person types: which / states / publish / warn / notices / coverage. * Standing rule (c319): a new HF dataset must be a COMPUTED CUT that owns a query no existing artifact answers — never "the same rows, filtered". This one has 51 rows a notice-level file cannot answer: per-jurisdiction depth and, for three states, a sourced NEGATIVE result. HONESTY RAILS (the same ones gen_coverage_page.py enforces — it is the SINGLE source of every fact here; this script only reshapes them): 1. Every number is recomputed from repo/data/coverage.json + repo/data/warn_notices.json on every run. Nothing is hand-typed. 2. `archive_start_year` is the earliest NOTICE DATE WE HOLD. It is a fact about the portal's depth and our scraping of it, never about when a state began requiring notices. The card says so in words. 3. Undated rows are counted and shown, never dropped; the denominator and the archive total appear in the same sentence (c340 rule). 4. No statutory citation. The three non-publishing rows say what we searched for, when, and what secondary sources report — and that we have not read the statute. The selftest FAILS if `§` / `Ark. Code` / `Wyo. Stat.` / `N.H. Rev.` appears anywhere in the card or CSV. 5. No comparison claim about a competitor's coverage. We say what we hold. Reads : repo/data/coverage.json, repo/data/warn_notices.json (via gen_coverage_page.facts()), sources.json (agency names + URLs) Writes: repo/data/warn_coverage_by_state.csv (CSV twin on GitHub), hf_coverage_staging/ then uploads to /DATASET_NAME Usage (cwd = product/): python3 hf_coverage.py --selftest HF_STAGE_ONLY=1 python3 hf_coverage.py .venv-hf/bin/python3 hf_coverage.py Env: HF_TOKEN. Non-fatal by convention in publish.sh. """ import csv import datetime import os import re import shutil import sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import dataviz # noqa: E402 import gen_coverage_page as cov # noqa: E402 import hf_offer # noqa: E402 import tiers # noqa: E402 DATASET_NAME = "which-us-states-publish-warn-act-layoff-notices-coverage" STAGE = "hf_coverage_staging" CSV_NAME = "warn_coverage_by_state.csv" REPO_CSV = os.path.join(HERE, "repo", "data", CSV_NAME) SITE = tiers.MIRROR_URL COVERAGE_PAGE = SITE + "coverage.html" REPO = hf_offer.REPO_URL ISSUES = hf_offer.ISSUES_URL NOTICE_DS = "https://huggingface.co/datasets/APProjects/us-warn-act-layoffs-notices-daily" SHALLOW_CUTOFF = 2010 FORBIDDEN = ("§", "Ark. Code", "Wyo. Stat.", "N.H. Rev.", "A.C.A.", "W.S. ") FIELDS = ["state", "state_name", "publishes_public_list", "notices_held", "dated_notices", "undated_notices", "archive_start_year", "latest_notice_date", "last_scraped", "portal_depth_note", "agency", "agency_url", "finding", "surveyed_on"] # ----------------------------------------------------------------- rows def build(f=None): """51 rows: the 48 publishing jurisdictions (from the live build) + the 3 states with no public list (from gen_coverage_page.NO_PUBLIC_LIST).""" f = f or cov.facts() rows = [] for d in f["states"]: first = d["first"] # sources.json keeps a few portal URLs as templates (FL: ...?year={year}); # a card row needs a URL a reader can click, so fill it with the latest year we hold. d["url"] = (d["url"] or "").replace("{year}", (d["latest"] or str(datetime.date.today().year))[:4]) note = "" if first and int(first) >= SHALLOW_CUTOFF: note = (f"Shallow: our earliest notice for this state is dated {first}. " "That is how far back the portal (or the archived copies we " "could reach) goes, not when layoffs began.") rows.append({ "state": d["st"], "state_name": d["name"], "publishes_public_list": "true", "notices_held": d["rows"], "dated_notices": d["dated"], "undated_notices": d["undated"], "archive_start_year": first, "latest_notice_date": d["latest"], "last_scraped": d["scraped"], "portal_depth_note": note, "agency": d["agency"], "agency_url": d["url"], "finding": "Public WARN notice list published by the state agency; " "read on every daily rebuild.", "surveyed_on": f["generated_at"][:10], }) for st, agency, url, finding in cov.NO_PUBLIC_LIST: rows.append({ "state": st, "state_name": cov.sname(st), "publishes_public_list": "false", "notices_held": 0, "dated_notices": 0, "undated_notices": 0, "archive_start_year": "", "latest_notice_date": "", "last_scraped": "", "portal_depth_note": "", "agency": agency, "agency_url": url, "finding": f"Searched {cov.SEARCHED_ON}: {finding}", "surveyed_on": cov.SEARCHED_ON, }) rows.sort(key=lambda r: (r["publishes_public_list"] != "true", -int(r["notices_held"]), r["state"])) stats = { "n_pub": f["n_pub"], "n_none": f["n_none"], "n_rows": len(rows), "total": f["total"], "dated": f["dated"], "undated": f["undated"], "first_year": f["first_year"], "asof": f["generated_at"][:10], "n_shallow": sum(1 for r in rows if r["portal_depth_note"]), "deep": sum(1 for r in rows if r["archive_start_year"] and int(r["archive_start_year"]) < 2000), } return {"rows": rows, "stats": stats} def write_csv(path, rows): os.makedirs(os.path.dirname(path), exist_ok=True) with open(path, "w", newline="", encoding="utf-8") as fh: w = csv.DictWriter(fh, fieldnames=FIELDS) w.writeheader() for r in rows: w.writerow(r) # ----------------------------------------------------------------- card CARD = """--- pretty_name: Which US states publish WARN Act layoff notices - coverage and archive depth by state license: cc-by-4.0 language: - en task_categories: - tabular-classification tags: - layoffs - warn-act - warn-notices - warn-coverage - state-coverage - data-coverage - public-records - government-data - labor-market - united-states - survey - daily-updated - tabular size_categories: - n<1K configs: - config_name: default data_files: - split: train path: data/{csv_name} --- # Which US states publish WARN Act layoff notices? {n_pub} do, {n_none} do not — coverage and archive depth for all {n_rows} jurisdictions **Rebuilt {asof}.** {n_pub} US jurisdictions ({n_pub_states} states + DC) run a public list of WARN Act layoff notices; we read every one of them daily and hold **{total:,} notices back to {first_year}** ({dated:,} carry a usable notice date, {undated:,} do not — counted, never dropped). **Three states publish no public list at all: Arkansas, New Hampshire and Wyoming.** So {n_pub} is not "{n_pub} of 51" — it is every jurisdiction that publishes, plus a sourced account of the three that do not. Puerto Rico, Guam and the US Virgin Islands are covered by the federal Act but run no public notice portal we could find. This table is the survey a data buyer normally has to do by hand before trusting any "50-state" claim. It is one row per jurisdiction: does the state publish, how many notices we hold, how far back the public archive actually goes, when it was last read, and — for the three that publish nothing — exactly what we searched for and what we found. ![Notices held per state, {n_pub} publishing jurisdictions](chart.svg) ## The three states with no public WARN list | State | Agency that receives WARN notices | What we found (searched {searched_on}) | |---|---|---| {none_table} We did **not** read the underlying statutes and this card does not cite them. If you know a public source for any of these three, [open an issue]({issues}) — it is read, and a working source ships in the next daily rebuild. ## Where the public archive is shallow — read this before you buy any "historical" WARN file "Archive starts" below is the **earliest notice date we hold** for a state. It is a fact about how far back that state's portal (or the archived copies we could reach) goes — not when the state began requiring notices, and not when layoffs began. {n_shallow} publishing jurisdictions start in {cutoff} or later; the largest of them are the ones that matter for any multi-year analysis: | State | Notices held | Archive starts | Latest notice | |---|---:|---:|---| {shallow_table} Only {deep} jurisdictions reach back before 2000. A ranking of "the biggest layoffs of 1995" from any WARN dataset is a ranking of the states that publish that far back, not of the country. We say this here so nobody learns it after paying. ## Every jurisdiction | State | Publishes a public list | Notices held | Dated | Archive starts | Latest notice | Last read | Agency | |---|---|---:|---:|---:|---|---|---| {full_table} ## Columns (`data/{csv_name}`, {n_rows} rows) - `state`, `state_name` — USPS code and name; DC included. - `publishes_public_list` — `true` if the state agency posts a public WARN notice list we read on every daily rebuild; `false` for the three that do not. - `notices_held` — rows in the live archive for that state on {asof}. - `dated_notices`, `undated_notices` — how many carry a parseable notice date. `dated + undated = notices_held`; undated rows exist mostly in SC and PA and are kept, flagged, in the notice-level file. - `archive_start_year` — year of the earliest dated notice we hold (see above). - `latest_notice_date`, `last_scraped` — freshness, per state. - `portal_depth_note` — filled for states whose archive starts in {cutoff} or later. - `agency`, `agency_url` — the state office that receives WARN notices. - `finding` — for publishing states, one line; for the three non-publishers, the dated search result and what secondary sources report. - `surveyed_on` — the build date for publishing states; the search date for the three non-publishers. ## Method The {n_pub} publishing rows are counted from the same daily build that produces the notice-level dataset ([{notice_ds_name}]({notice_ds})): {n_pub} state scrapers into one schema, employer names alias-merged, every row carrying its source URL. The three non-publishing rows are a manual survey: we searched each state's workforce-agency site and the open web on {searched_on}, found no public list, and recorded what secondary sources report — as a report of what we found, not a legal conclusion. Nothing on this card is typed by hand; the card, the chart and the CSV are written from one in-memory result on every run, and the build fails if a statutory citation appears. The same survey, as a page with the bar chart of the largest archives: [{coverage_page}]({coverage_page}). Scrapers and the coverage generator: [{repo}]({repo}). {offer} """ def _md(s): return str(s).replace("|", "\\|").replace("\n", " ") def render(res): rows, st = res["rows"], res["stats"] pub = [r for r in rows if r["publishes_public_list"] == "true"] none = [r for r in rows if r["publishes_public_list"] != "true"] if len(pub) < 40 or len(none) < 1: sys.exit(f"hf_coverage: refusing to render a thin survey ({len(pub)} publishing, {len(none)} none)") none_table = "\n".join( f"| **{_md(r['state_name'])}** ({r['state']}) | [{_md(r['agency'])}]({r['agency_url']}) | {_md(r['finding'])} |" for r in none) shallow = [r for r in pub if r["portal_depth_note"]] shallow.sort(key=lambda r: -int(r["notices_held"])) shallow_table = "\n".join( f"| {_md(r['state_name'])} ({r['state']}) | {int(r['notices_held']):,} | {r['archive_start_year']} | {r['latest_notice_date']} |" for r in shallow[:12]) full_table = "\n".join( f"| {_md(r['state_name'])} ({r['state']}) | {'yes' if r['publishes_public_list'] == 'true' else '**no**'} | " f"{int(r['notices_held']):,} | {int(r['dated_notices']):,} | {r['archive_start_year'] or '—'} | " f"{r['latest_notice_date'] or '—'} | {r['last_scraped'] or '—'} | " + (f"[{_md(r['agency'])}]({r['agency_url']})" if r["agency_url"] else _md(r["agency"])) + " |" for r in rows) offer = hf_offer.offer_block(st["total"], st["n_pub"], st["asof"]) card = CARD.format( csv_name=CSV_NAME, n_pub=st["n_pub"], n_none=st["n_none"], n_rows=st["n_rows"], asof=st["asof"], total=st["total"], dated=st["dated"], undated=st["undated"], n_pub_states=st["n_pub"] - sum(1 for r in pub if r["state"] == "DC"), first_year=st["first_year"], searched_on=cov.SEARCHED_ON, none_table=none_table, n_shallow=st["n_shallow"], cutoff=SHALLOW_CUTOFF, shallow_table=shallow_table, deep=st["deep"], full_table=full_table, issues=ISSUES, notice_ds=NOTICE_DS, notice_ds_name=NOTICE_DS.rsplit("/", 1)[-1], coverage_page=COVERAGE_PAGE, repo=REPO, offer=offer) top = sorted(pub, key=lambda r: -int(r["notices_held"]))[:16] svg = dataviz.bar_chart([(f"{r['state_name']} (from {r['archive_start_year'] or '?'})", int(r["notices_held"])) for r in top], unit="notices") check(card) return card, svg def check(text): for bad in FORBIDDEN: assert bad not in text, f"hf_coverage: statutory citation forbidden on this card: {bad!r}" left = re.findall(r"\{[a-z_0-9]+\}", text) assert not left, f"hf_coverage: unformatted placeholder {left}" assert "curl -s " not in text, "bare curl -s (files > 10 MB redirect; use -sL)" assert "50 states" not in text and "50-state" not in text.replace('"50-state"', ""), \ "never claim 50 states" # ----------------------------------------------------------------- stage / upload def stage(res): card, svg = render(res) root = os.path.join(HERE, STAGE) shutil.rmtree(root, ignore_errors=True) os.makedirs(os.path.join(root, "data"), exist_ok=True) open(os.path.join(root, "README.md"), "w", encoding="utf-8").write(card) open(os.path.join(root, "chart.svg"), "w", encoding="utf-8").write(svg) write_csv(os.path.join(root, "data", CSV_NAME), res["rows"]) for fn in ("hf_coverage.py", "gen_coverage_page.py", "dataviz.py"): shutil.copy2(os.path.join(HERE, fn), os.path.join(root, fn)) print(f"hf_coverage: staged {res['stats']['n_rows']} rows " f"({res['stats']['n_pub']} publishing, {res['stats']['n_none']} none) -> {STAGE}/") return root def upload(): token = os.environ.get("HF_TOKEN") if not token: print("HF_TOKEN not set - staged only, nothing uploaded.") return 0 from huggingface_hub import HfApi api = HfApi(token=token) user = api.whoami()["name"] repo_id = f"{user}/{DATASET_NAME}" api.create_repo(repo_id, repo_type="dataset", exist_ok=True) api.upload_folder(folder_path=os.path.join(HERE, STAGE), repo_id=repo_id, repo_type="dataset", commit_message="daily coverage-survey refresh") print(f"uploaded -> https://huggingface.co/datasets/{repo_id}") return 0 # ----------------------------------------------------------------- selftest def selftest(): def s(st, name, rows, dated, first, latest="2026-09-01", scraped="2026-09-12"): return {"st": st, "name": name, "rows": rows, "dated": dated, "undated": rows - dated, "first": first, "latest": latest, "scraped": scraped, "status": "ok", "agency": f"{name} Workforce", "url": f"https://example.gov/{st.lower()}"} states = [s(f"S{i:02d}", f"State {i}", 1000 - i, 990 - i, "1988" if i < 3 else "2016") for i in range(45)] states.append(s("CA", "California", 16587, 16500, "2014")) f = {"states": states, "total": sum(x["rows"] for x in states), "dated": sum(x["dated"] for x in states), "undated": sum(x["undated"] for x in states), "first_year": "1988", "generated_at": "2026-09-12T18:40Z", "n_pub": len(states), "n_none": len(cov.NO_PUBLIC_LIST)} res = build(f) rows, st = res["rows"], res["stats"] assert st["n_rows"] == len(states) + 3 and st["n_none"] == 3 assert rows[0]["state"] == "CA" and rows[0]["portal_depth_note"].startswith("Shallow") assert rows[-1]["publishes_public_list"] == "false" and rows[-1]["notices_held"] == 0 assert all(int(r["dated_notices"]) + int(r["undated_notices"]) == int(r["notices_held"]) for r in rows) assert st["deep"] == 3 and st["n_shallow"] == 43, (st["deep"], st["n_shallow"]) for r in rows: assert set(r) == set(FIELDS), set(r) ^ set(FIELDS) card, svg = render(res) assert "= len(rows) + 3 + 12, "tables missing rows" assert cov.SEARCHED_ON in card and "we have not read the statute" in card check(card) for bad in FORBIDDEN: # the CSV too assert not any(bad in str(v) for r in rows for v in r.values()), bad import tempfile tmp = tempfile.NamedTemporaryFile("w", suffix=".csv", delete=False); tmp.close() write_csv(tmp.name, rows) back = list(csv.DictReader(open(tmp.name, encoding="utf-8"))) assert len(back) == len(rows) and back[0]["state"] == "CA" os.unlink(tmp.name) print(f"hf_coverage selftest: ok ({len(rows)} rows in fixture, card {len(card)} chars)") return 0 def main(): if "--selftest" in sys.argv: return selftest() res = build() write_csv(REPO_CSV, res["rows"]) stage(res) if os.environ.get("HF_STAGE_ONLY"): print("HF_STAGE_ONLY set - not uploading.") return 0 return upload() if __name__ == "__main__": sys.exit(main())