Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Drop pillow as a required dependency #1365

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 0.17.0 ()
---------------------------

NOTE: This drops pillow as a required dependency.


Version 0.16.3 (2024-07-04)
---------------------------

Expand Down
7 changes: 6 additions & 1 deletion datashader/tests/test_tiles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

import pytest

import datashader as ds
import datashader.transfer_functions as tf

Expand Down Expand Up @@ -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'],
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion datashader/tests/test_transfer_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions datashader/tiles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
from importlib.util import find_spec
from io import BytesIO

import math
Expand All @@ -9,8 +10,6 @@

import numpy as np

from PIL.Image import fromarray

__all__ = ['render_tiles', 'MercatorTileDefinition']


Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion datashader/transfer_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ multipledispatch = "*"
numpy = "*"
pandas = "*"
param = "*"
pillow = "*"
pip = "*"
pyct = "*"
requests = "*"
Expand Down Expand Up @@ -64,6 +63,7 @@ holoviews = "*"
matplotlib-base = ">=3.3"
networkx = "*"
panel = ">1.1"
pillow = "*"
pyogrio = "*"
python-graphviz = "*"
python-snappy = "*"
Expand Down Expand Up @@ -96,6 +96,7 @@ geodatasets = "*"
geopandas-base = "*"
netcdf4 = "*"
pyarrow = "*"
pillow = "*"
pyogrio = "*"
rasterio = "*"
rioxarray = "*"
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ dependencies = [
'numpy',
'pandas',
'param',
'pillow',
'pyct',
'requests',
'scipy',
Expand Down