Files
stack/notebooks/pfs_reconciliation.py
kert 73017081ef fix(notebooks): stop rendering years as 2,027 — plain_years display cast (closes #643)
marimo's data-table viewer formats integer columns with thousands
separators, so int32/int64 year columns (DuckDB SELECT year, registry-
built frames) displayed as "2,027". New conf.display.plain_years casts
year-like integer columns (year, *_year, *_period; autodetected or
explicit, polars + pandas) to strings at the display boundary only —
analysis frames keep integer dtypes, chart encodings (already :O) are
untouched.

Applied at every affected display site: pfs_calcs carrier/SQL result
tables, pfs_reconciliation delta table, cy2026/cy2027 APM-threshold
tables, cms_quality_measures pipeline-result accordions. All five
notebooks re-executed headlessly in the notebooks container
(nb_integration ci-smoke set): pass=5, displayed year values now
serialize as strings.
2026-08-18 10:07:47 -04:00

116 lines
2.8 KiB
Python

import marimo
__generated_with = "0.21.1"
app = marimo.App(width="medium")
@app.cell(hide_code=True)
def _():
import marimo as mo
return (mo,)
@app.cell(hide_code=True)
def _(mo):
mo.md("""
# PFS Reconciliation
Runs `rec.pricers.pfs.PfsPricer` against `pfs.carrier_locality`
for a chosen year and reports the per-row delta. Goal is perfect
1:1 concordance. Tracks **homelab/stack#340**.
""")
return
@app.cell(hide_code=True)
def _():
from conf import connect
from conf.display import plain_years
from rec.engine import reconcile
from rec.pricers.pfs import PfsPricer
# PFS reference data lives in the DuckLake lakehouse (M5, #514);
# queries are unchanged — the lake is the default database.
con = connect.ducklake()
pricer = PfsPricer()
return con, plain_years, pricer, reconcile
@app.cell(hide_code=True)
def _(con, mo, pricer):
_years = pricer.years_available(con)
if not _years:
year_picker = mo.ui.dropdown(
options={"(no data loaded)": 0}, value="(no data loaded)", label="Year"
)
else:
year_picker = mo.ui.dropdown(
options={str(y): y for y in _years},
value=str(_years[-1]),
label="Year",
)
tolerance = mo.ui.slider(
start=0, stop=10, step=1, value=0, label="Tolerance (cents)"
)
mo.hstack([year_picker, tolerance], justify="start", gap=1)
return tolerance, year_picker
@app.cell(hide_code=True)
def _(con, mo, pricer, reconcile, tolerance, year_picker):
_year = int(year_picker.value) if year_picker.value else 0
if _year == 0:
result = None
mo.md("*Load `pfs.rvu`, `pfs.gpci`, and `pfs.carrier_locality` first.*")
else:
result = reconcile(pricer, con, _year, tolerance_cents=int(tolerance.value))
mo.md(result.summary_md(top_n=25))
return (result,)
@app.cell(hide_code=True)
def _(mo):
mo.md("""
## Delta table
Every row in the outer join, sorted by the largest absolute delta.
``is_exact`` uses the tolerance above; ``is_near`` is always a 1¢
window. Null ``fee_gt`` means the row is calculated-only; null
``fee_calc`` means ground-truth-only.
""")
return
@app.cell(hide_code=True)
def _(plain_years, result):
_deltas = plain_years(result.deltas) if result is not None else None
_deltas
return
@app.cell(hide_code=True)
def _(mo):
mo.md("""
## Warnings
Non-fatal issues surfaced by the engine — duplicate join keys,
missing columns, rule lookup failures, etc.
""")
return
@app.cell(hide_code=True)
def _(mo, result):
if result is None or not result.warnings:
mo.md("*(none)*")
else:
mo.md("\n".join(f"- {w}" for w in result.warnings))
return
if __name__ == "__main__":
app.run()