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
6 changes: 4 additions & 2 deletions docs/source/business_ch09_reporting_style_contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This chapter implements two things:

1) A reusable style/guardrails module:

- ``scripts/_reporting_style.py``
- ``pystatsv1.trackd.reporting_style`` (source: ``src/pystatsv1/trackd/reporting_style.py``)

2) A Chapter 9 driver that produces a small, compliant “chart pack” + manifest:

Expand All @@ -39,7 +39,9 @@ This chapter implements two things:
The style contract (rules)
--------------------------

The style contract lives in ``scripts/_reporting_style.py`` as ``STYLE_CONTRACT``.
The style contract lives in ``pystatsv1.trackd.reporting_style`` as ``STYLE_CONTRACT``.

Note: ``scripts/_reporting_style.py`` is kept as a small shim for backward compatibility with older Track D scripts and workbook templates.
It is intentionally conservative so later chapters can reuse it.

Allowed chart types
Expand Down
33 changes: 4 additions & 29 deletions scripts/_mpl_compat.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
"""Matplotlib compatibility helpers for workbook scripts.
"""Backward-compatible shim for Track D matplotlib helpers.

Matplotlib 3.9 renamed the Axes.boxplot keyword argument "labels" to
"tick_labels". The old name is deprecated and scheduled for removal.

These helpers keep our educational scripts working on Matplotlib 3.8+
while avoiding deprecation warnings on newer versions.
Historically, Track D chapter scripts imported :mod:`scripts._mpl_compat`.
The implementation now lives in :mod:`pystatsv1.trackd.mpl_compat`.
"""

from __future__ import annotations

from typing import Any, Sequence


def ax_boxplot(
ax: Any,
*args: Any,
tick_labels: Sequence[str] | None = None,
**kwargs: Any,
):
"""Call ``ax.boxplot`` with a 3.8/3.9+ compatible keyword.

Prefer ``tick_labels`` (Matplotlib >= 3.9). If that keyword is not
supported (Matplotlib <= 3.8), fall back to the legacy ``labels``.
"""

if tick_labels is None:
return ax.boxplot(*args, **kwargs)

try:
return ax.boxplot(*args, tick_labels=tick_labels, **kwargs)
except TypeError:
# Older Matplotlib: the new keyword doesn't exist.
return ax.boxplot(*args, labels=tick_labels, **kwargs)
from pystatsv1.trackd.mpl_compat import * # noqa: F401,F403
Loading