Skip to content

fix(scripts): import BarContainer from matplotlib.container - #52

Merged
mahdi-shafiei merged 1 commit into
mainfrom
fix/example-output-generator
Nov 8, 2026
Merged

mahdi-shafiei merged 1 commit into
mainfrom
fix/example-output-generator

Conversation

@mahdi-shafiei

Copy link
Copy Markdown
Collaborator

Summary

scripts/generate_example_outputs.py failed at import: scripts/_plot_helpers.py annotated label_bars with plt.BarContainer, which matplotlib.pyplot imports only under TYPE_CHECKING (matplotlib 3.10.9), so the annotation raised AttributeError when the module loaded.

 scripts/_plot_helpers.py
+from matplotlib.axes import Axes
+from matplotlib.container import BarContainer
 def label_bars(
-    ax: plt.Axes,  # type: ignore[type-arg]
-    bars: plt.BarContainer,  # type: ignore[type-arg]
+    ax: Axes,
+    bars: BarContainer,
 pyproject.toml  test extra: + matplotlib>=3.7   (uv.lock: the extra's metadata, no version change)
 tests/scripts/test_plot_helpers.py  (new)

The generator's simulated plots (training curves and ROC curves drawn from random numbers) belong to the drug-discovery pages they illustrate and are replaced in the docs change that regenerates those pages from real runs.

Evidence

  • Before: the new test fails at collection: AttributeError: module 'matplotlib.pyplot' has no attribute 'BarContainer'.
    After: tests/scripts 6 passed; pyright reports 0 errors on the helper with the ignores removed.
  • With this one change the full generator ran to completion on a scratch copy (52 plots, no errors).
  • uv lock --check passes; pre-commit passes on all files; tests/test_ci_shards.py passes.

Merge Danger

Door: two-way

Blast Radius: documentation scripts

scripts/_plot_helpers.py annotated label_bars with plt.BarContainer,
which matplotlib.pyplot imports for type checkers only, so importing the
helpers raised AttributeError and generate_example_outputs.py could not
start. The annotations now name matplotlib.container.BarContainer and
matplotlib.axes.Axes, and the type-ignore comments they carried go.

A test labels a bar chart through the helper; it failed at import before
the change. The test extra declares matplotlib, which the test imports
and which reached the test environment only through sibling packages.
@mahdi-shafiei
mahdi-shafiei marked this pull request as ready for review November 8, 2026 22:43
@mahdi-shafiei
mahdi-shafiei merged commit 3eb187c into main Nov 8, 2026
14 checks passed
@mahdi-shafiei
mahdi-shafiei deleted the fix/example-output-generator branch November 8, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant