Skip to content

Use plt.get_cmap instead of removed-in-3.11 plt.cm.get_cmap - #9

Merged
thorwhalen merged 1 commit into
masterfrom
fix/deprecated-plt-cm-get-cmap
Sep 22, 2026
Merged

thorwhalen merged 1 commit into
masterfrom
fix/deprecated-plt-cm-get-cmap

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

scatter_and_color_according_to_y resolved its colormap via plt.cm.get_cmap
(i.e. matplotlib.cm.get_cmap), which matplotlib deprecated in 3.7 with
removal='3.11'. Since the package pins no matplotlib upper bound, the
continuous-y branch of this public, __init__-exported function would start
raising AttributeError as soon as users pick up 3.11.

Switches to plt.get_cmap, the non-deprecated spelling matplotlib's own
warning points at. Verified equivalent under matplotlib 3.10 for every
argument form the call site can produce (str, Colormap, None) — same
colormap type, identical 256-sample lookup table, invalid input still raises
ValueError from both spellings. Observationally inert apart from dropping
the warning.

Adds a regression test asserting the float-y path emits no
MatplotlibDeprecationWarning.

No related open issue found (searched for "cmap"; #1 is about a different pair
of problems in the same function — an LDA/PCA fallback warning and a missing
ax.colorbar() — left untouched, out of scope here).

Branch sat pushed with red CI and no PR for two weeks (thorwhalen/fleet_stuff
cleanup). Verified: master has not moved since the branch was cut (no rebase
needed).

CI note: hosted CI is red on this branch, but for a pre-existing reason
unrelated to this change — the Validation (3.8) job fails at
Install dependencies (isee/wads now require Python 3.9+ syntax, the
workflow pins 3.8). Master's own last CI run fails identically
(https://github.com/i2mint/oplot/actions/runs/19587236188). Filed as #8;
out of scope to fix here. Gated instead on a direct pytest run in a fresh
venv with matplotlib 3.11.2 (the exact removal version) — no
pyproject.toml/[tool.wads.ci] in this repo, so wads ci-local doesn't
apply either. Result: 75/75 passed, including the new regression test.
--doctest-modules on the package also reproduces the two pre-existing,
unrelated failures the original commit called out (oplot/my.py importing a
nonexistent nympy module — confirmed present on unmodified master too — and
an unrelated plot_stats.smooth_scores doctest) — neither touched here.

🤖 Generated with Claude Code

`scatter_and_color_according_to_y` resolved its colormap via
`plt.cm.get_cmap` (i.e. `matplotlib.cm.get_cmap`), which matplotlib
deprecated in 3.7 with `removal='3.11'`. Since the package pins no
matplotlib upper bound, the continuous-`y` branch of this public,
`__init__`-exported function would start raising `AttributeError` as
soon as users pick up 3.11.

Switch to `plt.get_cmap`, the non-deprecated spelling matplotlib's own
warning points at.

Verified equivalent under matplotlib 3.10 for every argument form the
call site can produce -- str, `Colormap`, and `None` all yield the same
colormap type and an identical 256-sample lookup table, and invalid
input still raises `ValueError` from both spellings. The change is
therefore observationally inert apart from dropping the warning.

Adds a regression test asserting the float-`y` path emits no
`MatplotlibDeprecationWarning`; it fails on the unmodified code with the
`get_cmap ... will be removed in 3.11` message and passes after.

Suite: 74 passed before, 75 passed after (the one new test). Two
pre-existing failures under the CI `--doctest-modules` invocation are
untouched and unrelated: `oplot/my.py` fails to import (`nympy` typo)
and the `plot_stats.smooth_scores` doctest fails; both reproduce
identically on the unmodified tree.

Claude-Session: https://claude.ai/code/session_01L1aQPB34n7PU7jmbztSjBe
@thorwhalen
thorwhalen merged commit 6550520 into master Sep 22, 2026
2 of 4 checks passed
@thorwhalen
thorwhalen deleted the fix/deprecated-plt-cm-get-cmap branch September 22, 2026 12:57
thorwhalen added a commit that referenced this pull request Sep 22, 2026
#11)

* fix: migrate CI off legacy isee-based workflow onto wads-managed uv CI

Fixes #8: the legacy .github/workflows/ci.yml pinned Python 3.8 and
installed an unpinned isee (which pulls in wads); the currently-published
wads uses dict[str, Any] at module level, a TypeError on 3.8. Every push/PR
has shown red CI for this reason regardless of what changed, since before
#9 landed (gated on a local pytest run instead, per that PR's own notes).

Migration (durable fix option from #8, following the wads-migrate skill):
- setup.cfg/setup.py -> pyproject.toml (wads-migrate setup-to-pyproject),
  with the known rough edges fixed by hand: SPDX license string instead of
  the deprecated [project.license] text table; project_name set to "oplot";
  testpaths widened to ["oplot", "tests"] (the old CI actually ran
  `pytest --doctest-modules $PROJECT_NAME`, i.e. the package itself, so this
  preserves that doctest coverage rather than narrowing it to tests/ only);
  disabled the dead [tool.wads.ci.metrics] gate (config_path points at a
  file that doesn't exist, same pattern already fixed in git2py/focal).
- .github/workflows/ci.yml -> the modern uv-based template
  (wads-migrate ci-to-uv).

Widening test collection to the package surfaced two real, pre-existing
bugs invisible under the broken CI:
- oplot/my.py: `import nympy as np` (typo) made an already-orphaned,
  unimported module fail to even import. Fixed the typo; the module is
  still dead code (not referenced from oplot/__init__.py), out of scope
  here.
- oplot/plot_stats.py: smooth_scores's doctest asserted numpy<2.0's bare
  scalar repr (`[1.5]`, `[2, 3]`); currently-installed numpy 2.x reprs
  scalars as `np.float64(1.5)` / `np.int64(2)`. Not a logic bug -- updated
  the expected values to match current numpy's actual (correct) behavior.

Also applied `ruff format` fleet-wide (quote style, blank lines) to satisfy
the new CI's format-check gate -- no logic changes.

Dependents check: oplot's one known local dependent, `shaded`, only imports
`oplot.plot_data_set.scatter_and_color_according_to_y` (a module untouched
by this change); its test suite runs clean (2 skipped, needs audio fixtures
not present, 0 failed) against this branch.

Closes #8

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix: force MPLBACKEND=Agg in CI (Windows Tests hung on plt.show())

The Windows leg (just enabled by this branch's CI migration -- the old
workflow never had a Windows job at all) hung indefinitely instead of
completing: several oplot modules' doctests call plt.show(), and with no
non-interactive backend forced, matplotlib picked a GUI backend on the
Windows runner that blocked rather than no-op'ing (unlike Linux, which
has no DISPLAY and falls back to Agg automatically).

Set MPLBACKEND=Agg via [tool.wads.ci.env.defaults] (re-ran
wads-migrate ci-to-uv to wire it into the generated workflow's env: block).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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