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.
79 lines
2.5 KiB
Python
79 lines
2.5 KiB
Python
"""Tests for conf.display.plain_years (#643)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pandas as pd
|
|
import polars as pl
|
|
import pytest
|
|
|
|
from conf.display import plain_years
|
|
|
|
|
|
def test_autodetects_year_like_int_columns_polars() -> None:
|
|
df = pl.DataFrame(
|
|
{
|
|
"year": pl.Series([2026, 2027], dtype=pl.Int32),
|
|
"gpci_year": pl.Series([2027, 2027], dtype=pl.Int64),
|
|
"qp_performance_period": [2025, 2026],
|
|
"rows": [14518, 14169],
|
|
}
|
|
)
|
|
out = plain_years(df)
|
|
assert out["year"].to_list() == ["2026", "2027"]
|
|
assert out["gpci_year"].to_list() == ["2027", "2027"]
|
|
assert out["qp_performance_period"].to_list() == ["2025", "2026"]
|
|
# non-year integer columns keep their dtype (counts SHOULD group)
|
|
assert out.schema["rows"].is_integer()
|
|
# input frame is untouched
|
|
assert df.schema["year"] == pl.Int32
|
|
|
|
|
|
def test_explicit_columns_only() -> None:
|
|
df = pl.DataFrame({"year": [2027], "payment_year": [2029]})
|
|
out = plain_years(df, "year")
|
|
assert out.schema["year"] == pl.String
|
|
assert out.schema["payment_year"].is_integer()
|
|
|
|
|
|
def test_explicit_missing_column_raises() -> None:
|
|
df = pl.DataFrame({"year": [2027]})
|
|
with pytest.raises(KeyError):
|
|
plain_years(df, "yeer")
|
|
|
|
|
|
def test_non_integer_year_columns_are_left_alone() -> None:
|
|
df = pl.DataFrame({"year": ["2027"], "fiscal_year": [2026.5]})
|
|
out = plain_years(df)
|
|
assert out.schema == df.schema
|
|
|
|
|
|
def test_no_year_columns_is_a_noop() -> None:
|
|
df = pl.DataFrame({"hcpcs": ["99213"], "work_rvu": [1.3]})
|
|
assert plain_years(df) is df
|
|
|
|
|
|
def test_nulls_survive_polars() -> None:
|
|
df = pl.DataFrame({"year": pl.Series([2027, None], dtype=pl.Int64)})
|
|
assert plain_years(df)["year"].to_list() == ["2027", None]
|
|
|
|
|
|
def test_pandas_frames_supported() -> None:
|
|
df = pd.DataFrame({"performance_year": [2024, 2025], "codes": [10, 20]})
|
|
out = plain_years(df)
|
|
assert out["performance_year"].tolist() == ["2024", "2025"]
|
|
assert pd.api.types.is_integer_dtype(out["codes"])
|
|
# input untouched
|
|
assert pd.api.types.is_integer_dtype(df["performance_year"])
|
|
|
|
|
|
def test_pandas_nullable_int_with_na() -> None:
|
|
df = pd.DataFrame({"year": pd.array([2027, None], dtype="Int64")})
|
|
out = plain_years(df)
|
|
assert out["year"].tolist()[0] == "2027"
|
|
assert out["year"].tolist()[1] is None
|
|
|
|
|
|
def test_unsupported_type_raises() -> None:
|
|
with pytest.raises(TypeError):
|
|
plain_years({"year": [2027]})
|