Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions scripts/_mpl_compat.py
Original file line number Diff line number Diff line change
@@ -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",
]
42 changes: 38 additions & 4 deletions scripts/_reporting_style.py
Original file line number Diff line number Diff line change
@@ -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",
]
Binary file modified src/pystatsv1/assets/workbook_track_d.zip
Binary file not shown.
69 changes: 69 additions & 0 deletions tests/test_trackd_business_schema_shim_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)

Expand Down Expand Up @@ -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"
Expand All @@ -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
6 changes: 5 additions & 1 deletion workbooks/track_d_template/scripts/_mpl_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
36 changes: 35 additions & 1 deletion workbooks/track_d_template/scripts/_reporting_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]