Skip to content

Commit a471c05

Browse files
authored
compat: Pillow 11.3.0 (#1429)
1 parent 5df0841 commit a471c05

5 files changed

Lines changed: 28 additions & 15 deletions

File tree

datashader/mpl_ext.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,10 @@
1010
from . import transfer_functions as tf
1111
from .colors import Sets1to3
1212
from .core import bypixel, Canvas
13+
from .utils import uint32_to_uint8, uint8_to_uint32
1314

14-
__all__ = ["ScalarDSArtist", "CategoricalDSArtist", "alpha_colormap", "dsshow"]
15-
16-
17-
def uint32_to_uint8(img):
18-
"""Cast a uint32 raster to a 4-channel uint8 RGBA array."""
19-
return img.view(dtype=np.uint8).reshape(img.shape + (4,))
2015

21-
22-
def uint8_to_uint32(img):
23-
"""Cast a 4-channel uint8 RGBA array to uint32 raster"""
24-
return img.view(dtype=np.uint32).reshape(img.shape[:-1])
16+
__all__ = ["ScalarDSArtist", "CategoricalDSArtist", "alpha_colormap", "dsshow"]
2517

2618

2719
def to_ds_image(binned, rgba):

datashader/tiles.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
except ImportError:
1515
dask, db = None, None
1616

17+
18+
from .utils import uint32_to_uint8
19+
1720
__all__ = ['render_tiles', 'MercatorTileDefinition']
1821

1922

@@ -321,9 +324,14 @@ def render(self, da, level):
321324
if 0 in arr.shape:
322325
continue
323326

324-
# flip since y tiles go down (Google map tiles
325-
img = fromarray(np.flip(arr.data, 0), 'RGBA')
327+
# flip since y tiles go down (Google map tiles)
328+
data = np.flip(arr.data, 0)
329+
330+
# Create RGBA view for img
331+
if len(data.shape) == 2 and data.dtype == np.uint32:
332+
data = uint32_to_uint8(data)
326333

334+
img = fromarray(data)
327335
if self.post_render_func:
328336
extras = dict(x=x, y=y, z=z)
329337
img = self.post_render_func(img, **extras)

datashader/transfer_functions/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import xarray as xr
1313

1414
from datashader.colors import rgb, Sets1to3
15-
from datashader.utils import nansum_missing, ngjit
15+
from datashader.utils import nansum_missing, ngjit, uint32_to_uint8
1616

1717
try:
1818
import dask.array as da
@@ -39,7 +39,10 @@ def to_pil(self, origin='lower'):
3939
if cupy:
4040
data = cupy.asnumpy(data)
4141
arr = np.flipud(data) if origin == 'lower' else data
42-
return fromarray(arr, 'RGBA')
42+
43+
if len(arr.shape) == 2 and arr.dtype == np.uint32:
44+
arr = uint32_to_uint8(arr)
45+
return fromarray(arr)
4346

4447
def to_bytesio(self, format='png', origin='lower'):
4548
fp = BytesIO()

datashader/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,3 +1010,13 @@ def row_min_n_in_place_3d(ret, other):
10101010
for y in range(ny):
10111011
for x in range(nx):
10121012
_row_min_n_impl(ret[y, x], other[y, x])
1013+
1014+
1015+
def uint32_to_uint8(img):
1016+
"""Cast a uint32 raster to a 4-channel uint8 RGBA array."""
1017+
return img.view(dtype=np.uint8).reshape(img.shape + (4,))
1018+
1019+
1020+
def uint8_to_uint32(img):
1021+
"""Cast a 4-channel uint8 RGBA array to uint32 raster"""
1022+
return img.view(dtype=np.uint32).reshape(img.shape[:-1])

pixi.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ geodatasets = "*"
103103
geopandas-base = "*"
104104
netcdf4 = "*"
105105
pyarrow = "*"
106-
pillow = "<11.3.0" # Temp. upper pin
106+
pillow = "*"
107107
pyogrio = "*"
108108
rasterio = "*"
109109
rioxarray = "*"

0 commit comments

Comments
 (0)