Skip to content

Commit

Permalink
Handle zero-sized array reductions (#1979)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Oct 8, 2017
1 parent 3b11689 commit f3de8be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
16 changes: 16 additions & 0 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def _get_sampling(self, element, x, y):
x0, x1 = self.p.x_range
ex0, ex1 = element.range(x)
x_range = max([x0, ex0]), min([x1, ex1])
if x_range[0] == x_range[1]:
x_range = (x_range[0]-0.5, x_range[0]+0.5)

if self.p.expand or not self.p.y_range:
y_range = self.p.y_range or element.range(y)
else:
Expand All @@ -120,6 +123,18 @@ def _get_sampling(self, element, x, y):
width, height = self.p.width, self.p.height
(xstart, xend), (ystart, yend) = x_range, y_range

if not np.isfinite(xstart) and not np.isfinite(xend):
xstart, xend = 0, 1
elif xstart == xend:
xstart, xend = (xstart-0.5, xend+0.5)
x_range = (xstart, xend)

if not np.isfinite(ystart) and not np.isfinite(yend):
ystart, yend = 0, 1
elif ystart == yend:
ystart, yend = (ystart-0.5, yend+0.5)
y_range = (ystart, yend)

# Compute highest allowed sampling density
xspan = xend - xstart
yspan = yend - ystart
Expand All @@ -130,6 +145,7 @@ def _get_sampling(self, element, x, y):
xunit, yunit = float(xspan)/width, float(yspan)/height
xs, ys = (np.linspace(xstart+xunit/2., xend-xunit/2., width),
np.linspace(ystart+yunit/2., yend-yunit/2., height))

return (x_range, y_range), (xs, ys), (width, height)


Expand Down
7 changes: 5 additions & 2 deletions holoviews/operation/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,11 @@ def _process(self, view, key=None):
weights = weights[mask]
else:
weights = None
hist_range = find_minmax((np.nanmin(data), np.nanmax(data)), (0, -float('inf')))\
if self.p.bin_range is None else self.p.bin_range
try:
hist_range = find_minmax((np.nanmin(data), np.nanmax(data)), (0, -float('inf')))\
if self.p.bin_range is None else self.p.bin_range
except ValueError:
hist_range = (0, 1)

# Avoids range issues including zero bin range and empty bins
if hist_range == (0, 0):
Expand Down
5 changes: 4 additions & 1 deletion holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,10 @@ def _norm_kwargs(self, element, ranges, opts, vdim):
# Check whether the colorbar should indicate clipping
values = np.asarray(element.dimension_values(vdim))
if values.dtype.kind not in 'OSUM':
el_min, el_max = np.nanmin(values), np.nanmax(values)
try:
el_min, el_max = np.nanmin(values), np.nanmax(values)
except ValueError:
el_min, el_max = -np.inf, np.inf
else:
el_min, el_max = -np.inf, np.inf
vmin = -np.inf if opts['vmin'] is None else opts['vmin']
Expand Down

0 comments on commit f3de8be

Please sign in to comment.