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

Drop pillow as a required dependency #1365

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
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 @@ -42,7 +45,7 @@


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 @@ -58,11 +61,13 @@

# TODO: mark with slow_test
def test_render_tiles():
pytest.importorskip("PIL")

full_extent_of_data = (-500000, -500000,
500000, 500000)
levels = list(range(2))
output_path = 'test_tiles_output'
results = render_tiles(full_extent_of_data,

Check failure on line 70 in datashader/tests/test_tiles.py

View workflow job for this annotation

GitHub Actions / unit:test-39:ubuntu-latest

test_render_tiles ImportError: cannot import name 'fromarray' from 'PIL' (/home/runner/work/datashader/datashader/.pixi/envs/test-39/lib/python3.9/site-packages/PIL/__init__.py)

Check failure on line 70 in datashader/tests/test_tiles.py

View workflow job for this annotation

GitHub Actions / unit:test-312:ubuntu-latest

test_render_tiles ImportError: cannot import name 'fromarray' from 'PIL' (/home/runner/work/datashader/datashader/.pixi/envs/test-312/lib/python3.12/site-packages/PIL/__init__.py)

Check failure on line 70 in datashader/tests/test_tiles.py

View workflow job for this annotation

GitHub Actions / unit:test-39:macos-latest

test_render_tiles ImportError: cannot import name 'fromarray' from 'PIL' (/Users/runner/work/datashader/datashader/.pixi/envs/test-39/lib/python3.9/site-packages/PIL/__init__.py)

Check failure on line 70 in datashader/tests/test_tiles.py

View workflow job for this annotation

GitHub Actions / unit:test-312:macos-latest

test_render_tiles ImportError: cannot import name 'fromarray' from 'PIL' (/Users/runner/work/datashader/datashader/.pixi/envs/test-312/lib/python3.12/site-packages/PIL/__init__.py)
levels,
load_data_func=mock_load_data_func,
rasterize_func=mock_rasterize_func,
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():


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 import fromarray
hoxbro marked this conversation as resolved.
Show resolved Hide resolved

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 @@ numba = "*"
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
2 changes: 1 addition & 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 Expand Up @@ -95,4 +94,5 @@ log_cli_level = "INFO"
filterwarnings = [
"ignore:Passing a (SingleBlockManager|BlockManager) to (Series|GeoSeries|DataFrame|GeoDataFrame) is deprecated:DeprecationWarning", # https://github.com/holoviz/spatialpandas/issues/137
"ignore:Accessing the underlying geometries through the `.data`:DeprecationWarning:dask_geopandas.core", # https://github.com/geopandas/dask-geopandas/issues/264
"ignore:\\s*Dask dataframe query planning is disabled because dask-expr is not installed:FutureWarning", # OK
]
Loading