Skip to content

Commit

Permalink
Applied fixes and optimizations for datashader operations
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 4, 2019
1 parent 9ba17a7 commit 35edb92
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions holoviews/operation/datashader.py
Expand Up @@ -21,7 +21,7 @@

from ..core import (Operation, Element, Dimension, NdOverlay,
CompositeOverlay, Dataset, Overlay)
from ..core.data import PandasInterface, XArrayInterface
from ..core.data import PandasInterface, XArrayInterface, DaskInterface
from ..core.util import (
LooseVersion, basestring, cftime_types, cftime_to_timestamp,
datetime_types, dt_to_int, get_param_values, max_range)
Expand Down Expand Up @@ -115,13 +115,16 @@ def instance(self_or_cls,**params):

def _get_sampling(self, element, x, y, ndim=2, default=None):
target = self.p.target
if not isinstance(x, list) and x is not None:
x = [x]
if not isinstance(y, list) and y is not None:
y = [y]

if target:
x_range, y_range = target.range(x), target.range(y)
x0, y0, x1, y1 = target.bounds.lbrt()
x_range, y_range = (x0, x1), (y0, y1)
height, width = target.dimension_values(2, flat=False).shape
else:
if not isinstance(x, list) and x is not None:
x = [x]
if x is None:
x_range = self.p.x_range or (-0.5, 0.5)
elif self.p.expand or not self.p.x_range:
Expand All @@ -132,8 +135,6 @@ def _get_sampling(self, element, x, y, ndim=2, default=None):
x_range = (np.min([np.max([x0, ex0]), ex1]),
np.max([np.min([x1, ex1]), ex0]))

if not isinstance(y, list) and y is not None:
y = [y]
if (y is None and ndim == 2):
y_range = self.p.y_range or default or (-0.5, 0.5)
elif self.p.expand or not self.p.y_range:
Expand All @@ -156,7 +157,7 @@ def _get_sampling(self, element, x, y, ndim=2, default=None):
xtype = 'datetime'
elif not np.isfinite(xstart) and not np.isfinite(xend):
xstart, xend = 0, 0
if element.get_dimension_type(x) in datetime_types:
if x and element.get_dimension_type(x[0]) in datetime_types:
xtype = 'datetime'

ytype = 'numeric'
Expand All @@ -165,7 +166,7 @@ def _get_sampling(self, element, x, y, ndim=2, default=None):
ytype = 'datetime'
elif not np.isfinite(ystart) and not np.isfinite(yend):
ystart, yend = 0, 0
if element.get_dimension_type(y) in datetime_types:
if y and element.get_dimension_type(y[0]) in datetime_types:
ytype = 'datetime'

# Compute highest allowed sampling density
Expand Down Expand Up @@ -418,7 +419,7 @@ def _process(self, element, key=None):

if x is None or y is None or width == 0 or height == 0:
return self._empty_agg(element, x, y, width, height, xs, ys, agg_fn, **params)
elif not len(data):
elif not getattr(data, 'interface', None) is DaskInterface and not len(data):
empty_val = 0 if isinstance(agg_fn, ds.count) else np.NaN
xarray = xr.DataArray(np.full((height, width), empty_val),
dims=[y.name, x.name], coords={x.name: xs, y.name: ys})
Expand Down

0 comments on commit 35edb92

Please sign in to comment.