diff --git a/CHANGELOG.rst b/CHANGELOG.rst index aee31f038..0c1cd0665 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +Version 0.17.0 () +--------------------------- + +NOTE: This drops pillow as a required dependency. + + Version 0.16.3 (2024-07-04) --------------------------- diff --git a/datashader/tests/test_tiles.py b/datashader/tests/test_tiles.py index 143158ebb..ed23b85f1 100644 --- a/datashader/tests/test_tiles.py +++ b/datashader/tests/test_tiles.py @@ -1,4 +1,7 @@ from __future__ import annotations + +import pytest + import datashader as ds import datashader.transfer_functions as tf @@ -43,7 +46,7 @@ def mock_shader_func(agg, span=None): def mock_post_render_func(img, **kwargs): - from PIL import ImageDraw + ImageDraw = pytest.importorskip("PIL.ImageDraw") (x, y) = (5, 5) info = "x={} / y={} / z={}, w={}, h={}".format(kwargs['x'], @@ -59,6 +62,8 @@ def mock_post_render_func(img, **kwargs): # TODO: mark with slow_test def test_render_tiles(): + pytest.importorskip("PIL") + full_extent_of_data = (-500000, -500000, 500000, 500000) levels = list(range(2)) diff --git a/datashader/tests/test_transfer_functions.py b/datashader/tests/test_transfer_functions.py index 7bb3168d9..472fde761 100644 --- a/datashader/tests/test_transfer_functions.py +++ b/datashader/tests/test_transfer_functions.py @@ -5,7 +5,6 @@ import numpy as np import xarray as xr import dask.array as da -import PIL import pytest import datashader.transfer_functions as tf from datashader.tests.test_pandas import assert_eq_ndarray, assert_eq_xr, assert_image_close @@ -1123,11 +1122,14 @@ def test_eq_hist(rng): def test_Image_to_pil(): + PIL = pytest.importorskip('PIL') img = img1.to_pil() assert isinstance(img, PIL.Image.Image) def test_Image_to_bytesio(): + pytest.importorskip('PIL') + bytes = img1.to_bytesio() assert isinstance(bytes, BytesIO) assert bytes.tell() == 0 diff --git a/datashader/tiles.py b/datashader/tiles.py index 7f0969ac3..0b54d3c0f 100644 --- a/datashader/tiles.py +++ b/datashader/tiles.py @@ -1,4 +1,5 @@ from __future__ import annotations +from importlib.util import find_spec from io import BytesIO import math @@ -9,8 +10,6 @@ import numpy as np -from PIL.Image import fromarray - __all__ = ['render_tiles', 'MercatorTileDefinition'] @@ -292,11 +291,15 @@ def __init__(self, tile_definition, output_location, tile_format='PNG', self.tile_format = tile_format self.post_render_func = post_render_func + if find_spec("PIL") is None: + raise ImportError('pillow is required to render tiles') # TODO: add all the formats supported by PIL if self.tile_format not in ('PNG', 'JPG'): raise ValueError('Invalid output format') def render(self, da, level): + from PIL.Image import fromarray + xmin, xmax = self.tile_def.x_range ymin, ymax = self.tile_def.y_range extent = xmin, ymin, xmax, ymax diff --git a/datashader/transfer_functions/__init__.py b/datashader/transfer_functions/__init__.py index c75a6bdc0..ab03bb5fc 100644 --- a/datashader/transfer_functions/__init__.py +++ b/datashader/transfer_functions/__init__.py @@ -11,7 +11,6 @@ import toolz as tz import xarray as xr import dask.array as da -from PIL.Image import fromarray from datashader.colors import rgb, Sets1to3 from datashader.utils import nansum_missing, ngjit @@ -30,6 +29,8 @@ class Image(xr.DataArray): border=1 def to_pil(self, origin='lower'): + from PIL.Image import fromarray + data = self.data if cupy: data = cupy.asnumpy(data) diff --git a/pixi.toml b/pixi.toml index 1ac572cd7..94967642c 100644 --- a/pixi.toml +++ b/pixi.toml @@ -29,7 +29,6 @@ multipledispatch = "*" numpy = "*" pandas = "*" param = "*" -pillow = "*" pip = "*" pyct = "*" requests = "*" @@ -64,6 +63,7 @@ holoviews = "*" matplotlib-base = ">=3.3" networkx = "*" panel = ">1.1" +pillow = "*" pyogrio = "*" python-graphviz = "*" python-snappy = "*" @@ -96,6 +96,7 @@ geodatasets = "*" geopandas-base = "*" netcdf4 = "*" pyarrow = "*" +pillow = "*" pyogrio = "*" rasterio = "*" rioxarray = "*" diff --git a/pyproject.toml b/pyproject.toml index ff8aaf416..d1a748d33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,6 @@ dependencies = [ 'numpy', 'pandas', 'param', - 'pillow', 'pyct', 'requests', 'scipy',