From 0e10bb9f1cb4a7fe7575b33a3968ecbff1a7d5af Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 30 Apr 2025 12:33:43 +0300 Subject: [PATCH] fix: support numpy2 compatibility Since numpy2 we need to explicitly decide how to deal with values out of range. --- ipyvolume/serialize.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ipyvolume/serialize.py b/ipyvolume/serialize.py index 9e3ea147..9fb33c2f 100644 --- a/ipyvolume/serialize.py +++ b/ipyvolume/serialize.py @@ -99,7 +99,10 @@ def _cube_to_tiles(grid, vmin, vmax): subdata = data[y2d * Im.shape[0] : (y2d + 1) * Im.shape[0], x2d * Im.shape[1] : (x2d + 1) * Im.shape[1]] subdata[..., 3] = (Im * 255).astype(np.uint8) for i in range(3): - subdata[..., i] = ((gradient[i][zindex] / 2.0 + 0.5) * 255).astype(np.uint8) + subdata[..., i] = np.clip(np.nan_to_num( + (gradient[i][zindex] / 2.0 + 0.5) * 255, + nan=0, posinf=255, neginf=0), 0, 255 + ).astype(np.uint8) # for i in range(3): # subdata[...,i+1] = subdata[...,0] tile_shape = (grid.shape[2], grid.shape[1])