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

Make datashader.composite imports lazy #1222

Merged
merged 1 commit into from
May 26, 2023
Merged
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
11 changes: 10 additions & 1 deletion datashader/transfer_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from PIL.Image import fromarray

from datashader.colors import rgb, Sets1to3
from datashader.composite import composite_op_lookup, over, validate_operator
from datashader.utils import nansum_missing, ngjit

try:
Expand Down Expand Up @@ -116,6 +115,8 @@ def stack(*imgs, **kwargs):
how : str, optional
The compositing operator to combine pixels. Default is `'over'`.
"""
from datashader.composite import composite_op_lookup

if not imgs:
raise ValueError("No images passed in")
shapes = []
Expand Down Expand Up @@ -724,6 +725,8 @@ def set_background(img, color=None, name=None):
The background color. Can be specified either by name, hexcode, or as a
tuple of ``(red, green, blue)`` values.
"""
from datashader.composite import over

if not isinstance(img, Image):
raise TypeError("Expected `Image`, got: `{0}`".format(type(img)))
name = img.name if name is None else name
Expand Down Expand Up @@ -813,6 +816,8 @@ def apply_kernel(layer):
@tz.memoize
def _build_int_kernel(how, mask_size, ignore_zeros):
"""Build a spreading kernel for a given composite operator"""
from datashader.composite import composite_op_lookup, validate_operator

validate_operator(how, is_image=False)
op = composite_op_lookup[how + "_arr"]
@ngjit
Expand All @@ -837,6 +842,8 @@ def stencilled(arr, mask, out):
@tz.memoize
def _build_float_kernel(how, mask_size):
"""Build a spreading kernel for a given composite operator"""
from datashader.composite import composite_op_lookup, validate_operator

validate_operator(how, is_image=False)
op = composite_op_lookup[how + "_arr"]
@ngjit
Expand All @@ -861,6 +868,8 @@ def stencilled(arr, mask, out):
@tz.memoize
def _build_spread_kernel(how, is_image):
"""Build a spreading kernel for a given composite operator"""
from datashader.composite import composite_op_lookup, validate_operator

validate_operator(how, is_image=True)
op = composite_op_lookup[how + ("" if is_image else "_arr")]

Expand Down