diff --git a/scripts/_mpl_compat.py b/scripts/_mpl_compat.py index f0542e0..193941c 100644 --- a/scripts/_mpl_compat.py +++ b/scripts/_mpl_compat.py @@ -1,9 +1,17 @@ """Backward-compatible shim for Track D matplotlib helpers. -Historically, Track D chapter scripts imported :mod:`scripts._mpl_compat`. -The implementation now lives in :mod:`pystatsv1.trackd.mpl_compat`. +Historically, some Track D and workbook scripts imported +:mod:`scripts._mpl_compat`. + +The canonical implementation now lives in :mod:`pystatsv1.trackd.mpl_compat`. +This shim keeps existing imports working for students running scripts directly +from the repo. """ from __future__ import annotations -from pystatsv1.trackd.mpl_compat import * # noqa: F401,F403 +from pystatsv1.trackd.mpl_compat import ax_boxplot + +__all__ = [ + "ax_boxplot", +] diff --git a/scripts/_reporting_style.py b/scripts/_reporting_style.py index a229f35..1c3dc6a 100644 --- a/scripts/_reporting_style.py +++ b/scripts/_reporting_style.py @@ -1,12 +1,46 @@ """Backward-compatible shim for Track D reporting-style helpers. Historically, Track D chapter scripts imported :mod:`scripts._reporting_style`. -The implementation now lives in :mod:`pystatsv1.trackd.reporting_style`. +The canonical implementation now lives in :mod:`pystatsv1.trackd.reporting_style`. -Keeping this shim prevents template drift and avoids breaking older chapter -scripts that import from ``scripts/``. +Keeping this shim avoids breaking older chapter runners and keeps the repo and +workbook template aligned. """ from __future__ import annotations -from pystatsv1.trackd.reporting_style import * # noqa: F401,F403 +from pystatsv1.trackd.reporting_style import ( + FigureManifestRow, + FigureSpec, + STYLE_CONTRACT, + ensure_allowed_chart_type, + figure_manifest_to_frame, + mpl_context, + plot_bar, + plot_ecdf, + plot_histogram_with_markers, + plot_time_series, + plot_waterfall_bridge, + save_figure, + style_context, + write_contract_json, + write_style_contract_json, +) + +__all__ = [ + "STYLE_CONTRACT", + "FigureSpec", + "FigureManifestRow", + "write_style_contract_json", + "write_contract_json", + "mpl_context", + "style_context", + "save_figure", + "plot_time_series", + "plot_bar", + "plot_histogram_with_markers", + "plot_ecdf", + "plot_waterfall_bridge", + "figure_manifest_to_frame", + "ensure_allowed_chart_type", +] diff --git a/src/pystatsv1/assets/workbook_track_d.zip b/src/pystatsv1/assets/workbook_track_d.zip index aa235b0..3ccb56f 100644 Binary files a/src/pystatsv1/assets/workbook_track_d.zip and b/src/pystatsv1/assets/workbook_track_d.zip differ diff --git a/tests/test_trackd_business_schema_shim_smoke.py b/tests/test_trackd_business_schema_shim_smoke.py index d8f2884..d96a41f 100644 --- a/tests/test_trackd_business_schema_shim_smoke.py +++ b/tests/test_trackd_business_schema_shim_smoke.py @@ -7,9 +7,13 @@ import scripts._business_schema as shim import scripts._business_etl as etl_shim import scripts._business_recon as recon_shim +import scripts._mpl_compat as mpl_shim +import scripts._reporting_style as style_shim from pystatsv1.trackd._errors import TrackDSchemaError from pystatsv1.trackd import etl as trackd_etl +from pystatsv1.trackd import mpl_compat as trackd_mpl from pystatsv1.trackd import recon as trackd_recon +from pystatsv1.trackd import reporting_style as trackd_reporting_style from pystatsv1.trackd import schema as trackd_schema @@ -36,6 +40,24 @@ def test_business_recon_shim_exports_trackd_recon() -> None: assert recon_shim.BankReconOutputs is trackd_recon.BankReconOutputs +def test_mpl_compat_shim_exports_trackd_mpl_compat() -> None: + # The shim should re-export the package implementation (same function objects). + assert mpl_shim.ax_boxplot is trackd_mpl.ax_boxplot + + +def test_reporting_style_shim_exports_trackd_reporting_style() -> None: + # The shim should re-export the package implementation (same function objects). + assert style_shim.style_context is trackd_reporting_style.style_context + assert style_shim.save_figure is trackd_reporting_style.save_figure + assert style_shim.plot_time_series is trackd_reporting_style.plot_time_series + assert style_shim.plot_bar is trackd_reporting_style.plot_bar + assert style_shim.plot_histogram_with_markers is trackd_reporting_style.plot_histogram_with_markers + assert style_shim.plot_ecdf is trackd_reporting_style.plot_ecdf + assert style_shim.plot_waterfall_bridge is trackd_reporting_style.plot_waterfall_bridge + assert style_shim.FigureSpec is trackd_reporting_style.FigureSpec + assert style_shim.FigureManifestRow is trackd_reporting_style.FigureManifestRow + + def test_business_schema_shim_validate_schema_report_shape(tmp_path: Path) -> None: report = shim.validate_schema(tmp_path, dataset=trackd_schema.DATASET_NSO_V1) @@ -91,6 +113,31 @@ def test_track_d_template_business_recon_is_a_shim() -> None: assert "ar_rollforward_vs_tb" in text +def test_track_d_template_mpl_compat_is_a_shim() -> None: + root = Path(__file__).resolve().parents[1] + template = root / "workbooks" / "track_d_template" / "scripts" / "_mpl_compat.py" + assert template.exists() + + text = template.read_text(encoding="utf-8") + assert "pystatsv1.trackd.mpl_compat" in text + assert "ax_boxplot" in text + assert "__all__" in text + assert "import *" not in text + + +def test_track_d_template_reporting_style_is_a_shim() -> None: + root = Path(__file__).resolve().parents[1] + template = root / "workbooks" / "track_d_template" / "scripts" / "_reporting_style.py" + assert template.exists() + + text = template.read_text(encoding="utf-8") + assert "pystatsv1.trackd.reporting_style" in text + assert "style_context" in text + assert "save_figure" in text + assert "__all__" in text + assert "import *" not in text + + def test_repo_level_business_etl_shim_is_explicit() -> None: root = Path(__file__).resolve().parents[1] shim_path = root / "scripts" / "_business_etl.py" @@ -111,3 +158,25 @@ def test_repo_level_business_recon_shim_is_explicit() -> None: assert "pystatsv1.trackd.recon" in text assert "__all__" in text assert "import *" not in text + + +def test_repo_level_mpl_compat_shim_is_explicit() -> None: + root = Path(__file__).resolve().parents[1] + shim_path = root / "scripts" / "_mpl_compat.py" + assert shim_path.exists() + + text = shim_path.read_text(encoding="utf-8") + assert "pystatsv1.trackd.mpl_compat" in text + assert "__all__" in text + assert "import *" not in text + + +def test_repo_level_reporting_style_shim_is_explicit() -> None: + root = Path(__file__).resolve().parents[1] + shim_path = root / "scripts" / "_reporting_style.py" + assert shim_path.exists() + + text = shim_path.read_text(encoding="utf-8") + assert "pystatsv1.trackd.reporting_style" in text + assert "__all__" in text + assert "import *" not in text diff --git a/workbooks/track_d_template/scripts/_mpl_compat.py b/workbooks/track_d_template/scripts/_mpl_compat.py index d135899..a0b82d1 100644 --- a/workbooks/track_d_template/scripts/_mpl_compat.py +++ b/workbooks/track_d_template/scripts/_mpl_compat.py @@ -9,4 +9,8 @@ from __future__ import annotations -from pystatsv1.trackd.mpl_compat import * # noqa: F401,F403 +from pystatsv1.trackd.mpl_compat import ax_boxplot + +__all__ = [ + "ax_boxplot", +] diff --git a/workbooks/track_d_template/scripts/_reporting_style.py b/workbooks/track_d_template/scripts/_reporting_style.py index d58d60e..8331bf7 100644 --- a/workbooks/track_d_template/scripts/_reporting_style.py +++ b/workbooks/track_d_template/scripts/_reporting_style.py @@ -9,4 +9,38 @@ from __future__ import annotations -from pystatsv1.trackd.reporting_style import * # noqa: F401,F403 +from pystatsv1.trackd.reporting_style import ( + FigureManifestRow, + FigureSpec, + STYLE_CONTRACT, + ensure_allowed_chart_type, + figure_manifest_to_frame, + mpl_context, + plot_bar, + plot_ecdf, + plot_histogram_with_markers, + plot_time_series, + plot_waterfall_bridge, + save_figure, + style_context, + write_contract_json, + write_style_contract_json, +) + +__all__ = [ + "STYLE_CONTRACT", + "FigureSpec", + "FigureManifestRow", + "write_style_contract_json", + "write_contract_json", + "mpl_context", + "style_context", + "save_figure", + "plot_time_series", + "plot_bar", + "plot_histogram_with_markers", + "plot_ecdf", + "plot_waterfall_bridge", + "figure_manifest_to_frame", + "ensure_allowed_chart_type", +]