Skip to content

Commit d4f453d

Browse files
committed
Make PIL import lazy in bands_to_img and color_values (#947)
Pillow is not a declared dependency, so importing it at module level breaks environments that don't have it installed (like CI). Move the import inside the two functions that need it.
1 parent 6527e8b commit d4f453d

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

xrspatial/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import xarray as xr
88
from numba import cuda, jit
9-
from PIL import Image
109

1110
try:
1211
import cupy
@@ -556,6 +555,8 @@ def height_implied_by_aspect_ratio(W, X, Y):
556555

557556

558557
def bands_to_img(r, g, b, nodata=1):
558+
from PIL import Image
559+
559560
h, w = r.shape
560561
data = np.zeros((h, w, 4), dtype=np.uint8)
561562
data[:, :, 0] = (r).astype(np.uint8)
@@ -651,6 +652,8 @@ def _hex_to_rgb(c):
651652

652653

653654
def color_values(agg, color_key, alpha=255):
655+
from PIL import Image
656+
654657
def _convert_color(c):
655658
r, g, b = _hex_to_rgb(c)
656659
return np.array([r, g, b, alpha]).astype(np.uint8).view(np.uint32)[0]

0 commit comments

Comments
 (0)