From ba7129b078aee63fc6f1dd71be4e50147f7f0692 Mon Sep 17 00:00:00 2001 From: Matthias Schabel Date: Sun, 9 Aug 2026 13:59:17 -0700 Subject: [PATCH] fix: assign the over color to napari's high_color, not nan_color to_napari() checked for napari's high_color field but assigned the over color to nan_color, so high_color was never set and an explicitly configured bad color was silently replaced by the over color. Adds a regression test asserting that low_color, high_color, and nan_color each receive their own color. It requires napari >= 0.6.1, where those three fields were introduced. Co-Authored-By: Claude Opus 5 (1M context) Reviewed-By: Codex (gpt-5.6-sol, reasoning effort xhigh) --- src/cmap/_external.py | 2 +- tests/test_third_party.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cmap/_external.py b/src/cmap/_external.py index cb941c9c0..b9f8d5213 100644 --- a/src/cmap/_external.py +++ b/src/cmap/_external.py @@ -112,7 +112,7 @@ def to_napari(cm: Colormap) -> NapariColormap: if "nan_color" in param_names and cm.bad_color is not None: kwargs["nan_color"] = cm.bad_color.rgba if "high_color" in param_names and cm.over_color is not None: - kwargs["nan_color"] = cm.over_color.rgba + kwargs["high_color"] = cm.over_color.rgba if "low_color" in param_names and cm.under_color is not None: kwargs["low_color"] = cm.under_color.rgba return Colormap(**kwargs) diff --git a/tests/test_third_party.py b/tests/test_third_party.py index 66c2a9759..c07c0cb4b 100644 --- a/tests/test_third_party.py +++ b/tests/test_third_party.py @@ -73,6 +73,19 @@ def test_napari(qapp: "QApplication") -> None: v.close() +@pytest.mark.filterwarnings("ignore") +def test_napari_extreme_colors() -> None: + # nan_color/low_color/high_color were added in napari 0.6.1 + pytest.importorskip("napari", minversion="0.6.1") + + bad = "yellow" + ncm = Colormap(["black", "white"], under=UNDER, over=OVER, bad=bad).to_napari() + + np.testing.assert_allclose(ncm.low_color, Color(UNDER).rgba) + np.testing.assert_allclose(ncm.high_color, Color(OVER).rgba) + np.testing.assert_allclose(ncm.nan_color, Color(bad).rgba) + + @pytest.mark.skipif( sys.platform == "darwin" and sys.version_info >= (3, 13), reason="not yet working upstream",