Some checks failed
CI / lint (push) Successful in 45s
CI / notebooks-smoke (push) Successful in 1m40s
CI / lint (pull_request) Successful in 28s
CI / test (push) Failing after 3m39s
CI / notebooks-smoke (pull_request) Successful in 1m35s
CI / test (pull_request) Failing after 3m22s
Infra CI / notebooks (push) Successful in 1m0s
Infra CI / zotero (push) Successful in 17s
Infra CI / docs (push) Successful in 20s
Infra CI / api (push) Successful in 1m11s
Infra CI / bcda (push) Successful in 1m31s
Infra CI / mc (push) Successful in 16s
Infra CI / llm (push) Successful in 52s
Infra CI / zotero (pull_request) Successful in 23s
Infra CI / docs (pull_request) Successful in 16s
Infra CI / notebooks (pull_request) Successful in 58s
Infra CI / api (pull_request) Successful in 17s
Infra CI / bcda (pull_request) Successful in 16s
Infra CI / llm (pull_request) Successful in 20s
Infra CI / mc (pull_request) Successful in 17s
Local files land in the DuckDB mirror with the source headers kept: group labels, stacked IRS names, headerless code maps, and the HCPCS action key. The read-only explorer and the review page are wired at lead.fhirworx.io. OEWS now includes 2025.
56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""Which members of an IRS SOI zip are the county, ZIP, or CBSA tables.
|
|
|
|
A zip that contains a national CSV also contains one workbook per state
|
|
and, often, an ``.xls`` twin of that CSV. Loading every member would
|
|
repeat the same returns. State workbooks are the table only when the
|
|
zip has no national extract.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
_TABULAR = {".csv", ".txt", ".dat", ".xls", ".xlsx"}
|
|
_DELIMITED = {".csv", ".txt", ".dat"}
|
|
_NATIONAL = ("allagi", "allnoagi", "cyall", "zpall", "incyall")
|
|
|
|
|
|
def _kind(name: str) -> str:
|
|
base = Path(name).name.casefold()
|
|
suffix = Path(name).suffix.casefold()
|
|
if not base or suffix not in _TABULAR:
|
|
return ""
|
|
if "docguide" in base or "guide" in base:
|
|
return ""
|
|
if "cbsa" in base or "incbsa" in base:
|
|
return "cbsa"
|
|
if any(token in base for token in _NATIONAL):
|
|
return "national"
|
|
# 2005-2007 name the national ZIP file ``zipcode05.csv``, not ``zpall``.
|
|
stem = base[: -len(suffix)] if suffix else base
|
|
if suffix == ".csv" and stem.startswith("zipcode") and stem[7:].isdigit():
|
|
return "national"
|
|
if suffix == ".txt":
|
|
return ""
|
|
return "state"
|
|
|
|
|
|
def choose_irs_members(members: list[str]) -> list[str]:
|
|
"""National extracts and CBSA tables. State workbooks if that is all."""
|
|
classified = [(name, _kind(name)) for name in members]
|
|
classified = [(name, kind) for name, kind in classified if kind]
|
|
has_delimited_national = any(
|
|
kind == "national" and Path(name).suffix.casefold() in _DELIMITED
|
|
for name, kind in classified
|
|
)
|
|
has_national = any(kind == "national" for _, kind in classified)
|
|
chosen: list[str] = []
|
|
for name, kind in classified:
|
|
suffix = Path(name).suffix.casefold()
|
|
if kind == "national" and has_delimited_national and suffix not in _DELIMITED:
|
|
continue
|
|
if kind == "state" and has_national:
|
|
continue
|
|
chosen.append(name)
|
|
return chosen
|