From 820260b1d1ee0f08c39ff05b1e83939563604090 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 29 Sep 2026 22:14:23 +1000 Subject: [PATCH 1/7] Fix lookup issue with newer matplotlib --- ultraplot/colors.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ultraplot/colors.py b/ultraplot/colors.py index 08e4a655d..fba302a17 100644 --- a/ultraplot/colors.py +++ b/ultraplot/colors.py @@ -536,7 +536,7 @@ def _make_segment_data(values, coords=None, ratios=None): coords = np.atleast_1d(coords) if ratios is not None: warnings._warn_ultraplot( - f"Segment coordinates were provided, ignoring " f"ratios={ratios!r}." + f"Segment coordinates were provided, ignoring ratios={ratios!r}." ) if len(coords) != len(values) or coords[0] != 0 or coords[-1] != 1: raise ValueError(f"Coordinates must range from 0 to 1, got {coords!r}.") @@ -793,8 +793,7 @@ def _get_data(self, ext, alpha=True): data = "\n".join(" ".join(f"{num:0.6f}" for num in line) for line in data) else: raise ValueError( - f"Invalid extension {ext!r}. Options are: " - "'hex', 'txt', 'rgb', 'rgba'." + f"Invalid extension {ext!r}. Options are: 'hex', 'txt', 'rgb', 'rgba'." ) return data @@ -3107,6 +3106,15 @@ def __init__(self, kwargs): # These are converted to ultraplot's own colormap objects # on the fly when they are first accessed. + def __contains__(self, key): + # Work around for mpl 3.11.2 as it is not allowed to + # this piece of code will allow look up to both occur in our flattened representation (e.g. 'fire') as well as the original "Fire" + try: + key = self._translate_key(key, mirror=True) + except (KeyError, TypeError): + return False + return key in self._cmaps + def _translate_deprecated(self, key): """ Check if a colormap has been deprecated. From 4a05d1ff9aa819b4974c32a1554170b43c65f229 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 29 Sep 2026 22:17:55 +1000 Subject: [PATCH 2/7] Add smoke test --- ultraplot/tests/test_colormap.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ultraplot/tests/test_colormap.py b/ultraplot/tests/test_colormap.py index 882b5aaa0..6eefefcc0 100644 --- a/ultraplot/tests/test_colormap.py +++ b/ultraplot/tests/test_colormap.py @@ -1,4 +1,7 @@ -import ultraplot as uplt, pytest, numpy as np +import numpy as np +import pytest + +import ultraplot as uplt def test_colormap_reversal(): @@ -7,6 +10,11 @@ def test_colormap_reversal(): cmap = uplt.Colormap("rainbow") cmap_r = cmap.reversed() for i in range(256): - assert np.allclose( - cmap(i), cmap_r(255 - i) - ), f"Reversed colormap mismatch at index {i}" + assert np.allclose(cmap(i), cmap_r(255 - i)), ( + f"Reversed colormap mismatch at index {i}" + ) + + +def test_colormap_name_sensitivty(): + assert "fire" in uplt.colormaps + assert "Fire" in uplt.colormaps From acd4abafda59ea60eb7436ed8aaf634019f9ecdb Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 29 Sep 2026 22:18:33 +1000 Subject: [PATCH 3/7] Black --- ultraplot/tests/test_colormap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ultraplot/tests/test_colormap.py b/ultraplot/tests/test_colormap.py index 6eefefcc0..dc1d9ffa0 100644 --- a/ultraplot/tests/test_colormap.py +++ b/ultraplot/tests/test_colormap.py @@ -10,9 +10,9 @@ def test_colormap_reversal(): cmap = uplt.Colormap("rainbow") cmap_r = cmap.reversed() for i in range(256): - assert np.allclose(cmap(i), cmap_r(255 - i)), ( - f"Reversed colormap mismatch at index {i}" - ) + assert np.allclose( + cmap(i), cmap_r(255 - i) + ), f"Reversed colormap mismatch at index {i}" def test_colormap_name_sensitivty(): From ab95fe823322f4a51c8590051c0713a6d89c520b Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 29 Sep 2026 22:29:14 +1000 Subject: [PATCH 4/7] Fix v2 --- ultraplot/colors.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ultraplot/colors.py b/ultraplot/colors.py index fba302a17..005883731 100644 --- a/ultraplot/colors.py +++ b/ultraplot/colors.py @@ -3110,8 +3110,9 @@ def __contains__(self, key): # Work around for mpl 3.11.2 as it is not allowed to # this piece of code will allow look up to both occur in our flattened representation (e.g. 'fire') as well as the original "Fire" try: + key = self._translate_deprecated(key) key = self._translate_key(key, mirror=True) - except (KeyError, TypeError): + except (KeyError, TypeError, ValueError): return False return key in self._cmaps From 03d4704fb26d1237672e8d746f208d6e20823e63 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 29 Sep 2026 22:36:57 +1000 Subject: [PATCH 5/7] Fix v3 --- ultraplot/colors.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ultraplot/colors.py b/ultraplot/colors.py index 005883731..0604b715b 100644 --- a/ultraplot/colors.py +++ b/ultraplot/colors.py @@ -3114,7 +3114,20 @@ def __contains__(self, key): key = self._translate_key(key, mirror=True) except (KeyError, TypeError, ValueError): return False - return key in self._cmaps + + # Directly registered colormap + if self._has_item(key): + return True + + # Dynamically generated shifted colormap + if key.endswith("_s"): + key = key.removesuffix("_s") + + # Dynamically generated reversed colormap + if key.endswith("_r"): + key = key.removesuffix("_r") + + return self._has_item(key) def _translate_deprecated(self, key): """ From f2bfb6de1aefa1fda9372e3a7649343b00ede512 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Wed, 30 Sep 2026 10:06:54 +1000 Subject: [PATCH 6/7] Update the tests --- ultraplot/tests/test_colormap.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ultraplot/tests/test_colormap.py b/ultraplot/tests/test_colormap.py index dc1d9ffa0..18ce3143e 100644 --- a/ultraplot/tests/test_colormap.py +++ b/ultraplot/tests/test_colormap.py @@ -10,11 +10,16 @@ def test_colormap_reversal(): cmap = uplt.Colormap("rainbow") cmap_r = cmap.reversed() for i in range(256): - assert np.allclose( - cmap(i), cmap_r(255 - i) - ), f"Reversed colormap mismatch at index {i}" + assert np.allclose(cmap(i), cmap_r(255 - i)), ( + f"Reversed colormap mismatch at index {i}" + ) def test_colormap_name_sensitivty(): assert "fire" in uplt.colormaps assert "Fire" in uplt.colormaps + assert "fire_r" in uplt.colormaps + assert "fire_s" in uplt.colormaps + + with pytest.raises(KeyError): + uplt.colormaps["should_not_exist"] From cf87c9223b8d96ba72b24cf8ffd9ff6fc3c7f5f4 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Wed, 30 Sep 2026 10:07:50 +1000 Subject: [PATCH 7/7] Need to change zed to use black --- ultraplot/tests/test_colormap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ultraplot/tests/test_colormap.py b/ultraplot/tests/test_colormap.py index 18ce3143e..1adeab277 100644 --- a/ultraplot/tests/test_colormap.py +++ b/ultraplot/tests/test_colormap.py @@ -10,9 +10,9 @@ def test_colormap_reversal(): cmap = uplt.Colormap("rainbow") cmap_r = cmap.reversed() for i in range(256): - assert np.allclose(cmap(i), cmap_r(255 - i)), ( - f"Reversed colormap mismatch at index {i}" - ) + assert np.allclose( + cmap(i), cmap_r(255 - i) + ), f"Reversed colormap mismatch at index {i}" def test_colormap_name_sensitivty():