Skip to content

[SC-18206] Fix tests broken by Plotly 7 and NumPy 2 upstream removals - #557

Merged
juanmleng merged 3 commits into
mainfrom
juanmleng/sc-18206/replace-removed-plotly-figure-factory-calls
Sep 1, 2026
Merged

juanmleng merged 3 commits into
mainfrom
juanmleng/sc-18206/replace-removed-plotly-figure-factory-calls

Conversation

@juanmleng

@juanmleng juanmleng commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Description

What and why?

Plotly 7.0.0 (released 2026-08-25) removed create_annotated_heatmap and create_distplot. We allow plotly (>=6.0.0) with no upper bound, so any environment built since then gets Plotly 7 and five tests fail with AttributeError: ConfusionMatrix, RegressionResidualsPlot, TimeSeriesMissingValues, LaggedCorrelationHeatmap and TargetPredictionDistributionPlot. Older environments are unaffected, which is why this appeared with no change on our side.

The three heatmaps now use go.Heatmap with text/texttemplate. The two KDE plots call scipy.stats.gaussian_kde directly — the same thing create_distplot did internally, so the curves are identical to floating point. The plots look the same as before.

No version cap is added. The code runs on Plotly 6 and 7, and texttemplate has existed since Plotly 5.5, so a cap would restrict users without protecting them.

Two smaller things came along: RegressionResidualsPlot now raises MissingDependencyError for scipy like the other statistical tests instead of a bare ImportError, and GiniCoefficient used np.trapz, which NumPy 2 removed — that broke it on Python 3.14, where we resolve numpy>=2.3.

How to test

The bug is invisible on Plotly 6, so run the suite on both:

uv run python -m tests.test_unit_tests      # green
uv run pip install "plotly==7.0.0"
uv run python -m tests.test_unit_tests      # green here, 14 errors on main
uv run pip install "plotly==6.7.0"

Four new test files cover ConfusionMatrix, RegressionResidualsPlot, TargetPredictionDistributionPlot and GiniCoefficient — none had any test, which is why only one of the five failures was spotted originally. Every figure was also rendered to PNG before and after and compared.

What needs special review?

The confusion matrix orientation. create_annotated_heatmap and px.imshow disagree about which corner is the origin, so porting via px.imshow would silently transpose the matrix — TN and TP swapped, no error. This uses go.Heatmap, which keeps z as given, and the new tests assert each quadrant's label.

Also: the choice not to cap Plotly, and whether the NumPy fix belongs here — it is a different upstream and could be split out. It is included because it is one line and the same kind of failure.

Dependencies, breaking changes, and deployment notes

No dependency changes, no breaking changes. Until this ships, affected users can run pip install "plotly<7" and restart their kernel.

Release notes

Fixed five tests that failed with an AttributeError on Plotly 7.0.0 and later, which removed the helpers they used to draw heatmaps and distribution curves: ConfusionMatrix, RegressionResidualsPlot, TimeSeriesMissingValues, LaggedCorrelationHeatmap and TargetPredictionDistributionPlot. The plots are unchanged and now work on both Plotly 6 and 7, so no version pin is needed. Also fixed GiniCoefficient, which failed on Python 3.14 because of a renamed NumPy function.

Checklist

  • What and why
  • Screenshots or videos (Frontend)
  • How to test
  • What needs special review
  • Dependencies, breaking changes, and deployment notes
  • Labels applied
  • PR linked to Shortcut
  • Unit tests added (Backend)
  • Tested locally
  • Documentation updated (if required)
  • Environment variable additions/changes documented (if required)

Plotly 7.0.0 removed create_annotated_heatmap and create_distplot, so five
tests raised AttributeError on any environment that resolved Plotly 7.

Port the three heatmaps to go.Heatmap with native text/texttemplate, which
renders the same array in the same orientation, and compute the two KDE
curves with scipy.stats.gaussian_kde directly — the same 500-point estimate
create_distplot made internally, so the curves are unchanged to floating
point. TargetPredictionDistributionPlot was building two whole distplot
figures only to read their x/y off them, so it loses more code than it gains.

RegressionResidualsPlot gains the guarded scipy import the other statistical
tests already use; it depended on scipy through create_distplot but let a
bare ImportError escape.

Keep the dependency at plotly (>=6.0.0) with no upper bound. The ported code
runs on both majors, and texttemplate has been available on go.Heatmap since
Plotly 5.5, so a cap would constrain users without protecting them.

Add unit tests for ConfusionMatrix, RegressionResidualsPlot and
TargetPredictionDistributionPlot, none of which had any — the reason only one
of the five broken tests was identified from the report.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@juanmleng juanmleng self-assigned this Sep 1, 2026
@juanmleng juanmleng added the bug Something isn't working label Sep 1, 2026
@juanmleng
juanmleng marked this pull request as ready for review September 1, 2026 21:02
The Python 3.14 dependency leg resolves numpy>=2.3, where np.trapz no
longer exists — it was renamed to np.trapezoid. Resolve the name once
through getattr, which short-circuits on NumPy 2 before touching the
missing attribute and still finds trapz on NumPy 1.

GiniCoefficient is library code and had no test at all, so nothing caught
that it raises AttributeError for anyone on Python 3.14. Add one, along
with the same fallback in the residuals test added earlier on this branch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@juanmleng juanmleng changed the title [SC-18206] Plotly 7.0.0 removes figure_factory functions — 5 tests fail on clean installs [SC-18206] Fix tests broken by Plotly 7 and NumPy 2 upstream removals Sep 1, 2026
@juanmleng
juanmleng marked this pull request as draft September 1, 2026 21:12
@juanmleng
juanmleng marked this pull request as ready for review September 1, 2026 21:14
@juanmleng
juanmleng requested a review from cachafla September 1, 2026 21:14
@juanmleng
juanmleng merged commit 16810f6 into main Sep 1, 2026
27 checks passed
@juanmleng
juanmleng deleted the juanmleng/sc-18206/replace-removed-plotly-figure-factory-calls branch September 1, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants