From 03fa2ffef8bf18c0f56b4afcdc43358e031e4984 Mon Sep 17 00:00:00 2001 From: abhi-0203 Date: Tue, 11 Aug 2026 04:46:46 +0000 Subject: [PATCH] fix: handle scalar input with bytes=True in Colormap.__call__ When bytes=True and a scalar input is provided, the LUT is converted to uint8 before indexing. The resulting 4-element uint8 array was passed directly to Color(), which expects float values in [0, 1]. This raised ValueError: 'Invalid color array: array([32, 144, 140, 255], dtype=uint8)'. Fix: when bytes=True and the input is scalar, normalize the uint8 RGBA values back to [0, 1] float range before constructing Color(). The quantization to 8-bit is preserved in the rounding. Closes #153 --- src/cmap/_colormap.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmap/_colormap.py b/src/cmap/_colormap.py index 97a0272e4..03e12bf20 100644 --- a/src/cmap/_colormap.py +++ b/src/cmap/_colormap.py @@ -442,7 +442,12 @@ def __call__( xa[mask_bad] = N + 2 rgba = lut.take(xa, axis=0, mode="clip") - return rgba if np.iterable(x) else Color(rgba) + if np.iterable(x): + return rgba + if bytes: + # Normalize uint8 RGBA back to [0,1] float for Color constructor + return Color(rgba / 255) + return Color(rgba) def with_extremes( self,