Context
ergodic_insurance/visualization/batch_plots.py:20 does a hard module-top
import plotly.graph_objects as go, and visualization/__init__.py imports batch_plots
eagerly. So if plotly is absent, importing the visualization package raises
ModuleNotFoundError: No module named 'plotly' at import time, which cascades into ~26
unrelated reporting tests (test_misc_gaps_coverage.py::TestTableGenerator::*,
TestScenarioComparator::*) — none of which use plotly.
This is not a correctness bug and does not affect CI: plotly>=5.18.0 is a declared
dependency (pyproject.toml [project].dependencies), so CI and the project .venv have it
and these tests pass. It surfaced only when running tests on an interpreter that lacked plotly.
This issue is an optional robustness / dev-ergonomics hardening so one missing
(optional-feeling) dependency can't take down the entire viz package import + dozens of
unrelated tests.
Scope
Only one function uses plotly: plot_parameter_sweep_3d (go.Figure, go.Scatter3d,
and the return annotation -> go.Figure). The other four plotters
(plot_scenario_comparison, plot_sensitivity_heatmap, plot_scenario_convergence,
plot_parallel_scenarios) are matplotlib-only.
Proposed change
- Move
import plotly.graph_objects as go from module scope into plot_parameter_sweep_3d.
- Make the return annotation not require
go at import time — from __future__ import annotations, a string annotation -> "go.Figure", or -> Any.
- Optionally wrap the in-function import in
try/except ImportError with a friendly
"pip install plotly" hint.
Acceptance criteria
Notes
Surfaced during PR #1655 review. Lower priority because CI and .venv are unaffected — this
only bites a partial/non-.venv local environment.
Context
ergodic_insurance/visualization/batch_plots.py:20does a hard module-topimport plotly.graph_objects as go, andvisualization/__init__.pyimportsbatch_plotseagerly. So if
plotlyis absent, importing the visualization package raisesModuleNotFoundError: No module named 'plotly'at import time, which cascades into ~26unrelated reporting tests (
test_misc_gaps_coverage.py::TestTableGenerator::*,TestScenarioComparator::*) — none of which use plotly.This is not a correctness bug and does not affect CI:
plotly>=5.18.0is a declareddependency (
pyproject.toml[project].dependencies), so CI and the project.venvhave itand these tests pass. It surfaced only when running tests on an interpreter that lacked plotly.
This issue is an optional robustness / dev-ergonomics hardening so one missing
(optional-feeling) dependency can't take down the entire viz package import + dozens of
unrelated tests.
Scope
Only one function uses plotly:
plot_parameter_sweep_3d(go.Figure,go.Scatter3d,and the return annotation
-> go.Figure). The other four plotters(
plot_scenario_comparison,plot_sensitivity_heatmap,plot_scenario_convergence,plot_parallel_scenarios) are matplotlib-only.Proposed change
import plotly.graph_objects as gofrom module scope intoplot_parameter_sweep_3d.goat import time —from __future__ import annotations, a string annotation-> "go.Figure", or-> Any.try/except ImportErrorwith a friendly"
pip install plotly" hint.Acceptance criteria
import ergodic_insurance.visualization(andergodic_insurance.visualization.batch_plots) succeeds whenplotlyis not installed.TestTableGenerator/TestScenarioComparator) collect and pass without plotly installed.plot_parameter_sweep_3dstill works when plotly IS installed, and raises a clear, actionable error when it is not.plotlystays a declared dependency (making it an optional extra is out of scope here).Notes
Surfaced during PR #1655 review. Lower priority because CI and
.venvare unaffected — thisonly bites a partial/non-
.venvlocal environment.