Skip to content

Commit

Permalink
Merge pull request #5323 from radarhere/imagefilter_numpy
Browse files Browse the repository at this point in the history
Only import numpy when necessary
  • Loading branch information
hugovk committed Mar 28, 2021
2 parents 9a683db + 188d4f6 commit b3a1de9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/PIL/ImageFilter.py
Expand Up @@ -16,11 +16,6 @@
#
import functools

try:
import numpy
except ImportError: # pragma: no cover
numpy = None


class Filter:
pass
Expand Down Expand Up @@ -369,6 +364,13 @@ def __init__(self, size, table, channels=3, target_mode=None, **kwargs):
items = size[0] * size[1] * size[2]
wrong_size = False

numpy = None
if hasattr(table, "shape"):
try:
import numpy
except ImportError: # pragma: no cover
pass

if numpy and isinstance(table, numpy.ndarray):
if copy_table:
table = table.copy()
Expand Down

0 comments on commit b3a1de9

Please sign in to comment.