Skip to content

Commit

Permalink
Only import numpy when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 12, 2021
1 parent f91f93e commit 188d4f6
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 188d4f6

Please sign in to comment.