Skip to content

Commit

Permalink
Merge 4f338bb into 5e29725
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 4, 2018
2 parents 5e29725 + 4f338bb commit 646f97f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 28 deletions.
18 changes: 2 additions & 16 deletions holoviews/core/util.py
Expand Up @@ -810,20 +810,6 @@ def find_range(values, soft_range=[]):
return (None, None)


def is_finite(value):
"""
Safe check whether a value is finite, only None, NaN and inf
values are considered non-finite and allows checking all types not
restricted to numeric types.
"""
if value is None:
return False
try:
return np.isfinite(value)
except:
return True


def max_range(ranges, combined=True):
"""
Computes the maximal lower and upper bounds from a list bounds.
Expand Down Expand Up @@ -882,8 +868,8 @@ def dimension_range(lower, upper, hard_range, soft_range, padding=None, log=Fals
lower, upper = range_pad(lower, upper, padding, log)
lower, upper = max_range([(lower, upper), soft_range])
dmin, dmax = hard_range
lower = lower if dmin is None or not np.isfinite(dmin) else dmin
upper = upper if dmax is None or not np.isfinite(dmax) else dmax
lower = lower if dmin is None or not isfinite(dmin) else dmin
upper = upper if dmax is None or not isfinite(dmax) else dmax
return lower, upper


Expand Down
2 changes: 1 addition & 1 deletion holoviews/element/raster.py
Expand Up @@ -284,7 +284,7 @@ def __init__(self, data, kdims=None, vdims=None, bounds=None, extents=None,
l, b, r, t = bounds.lbrt()
xdensity = xdensity if xdensity else util.compute_density(l, r, dim1, self._time_unit)
ydensity = ydensity if ydensity else util.compute_density(b, t, dim2, self._time_unit)
if not np.isfinite(xdensity) or not np.isfinite(ydensity):
if not util.isfinite(xdensity) or not util.isfinite(ydensity):
raise ValueError('Density along Image axes could not be determined. '
'If the data contains only one coordinate along the '
'x- or y-axis ensure you declare the bounds and/or '
Expand Down
2 changes: 1 addition & 1 deletion holoviews/operation/stats.py
Expand Up @@ -102,7 +102,7 @@ def _process(self, element, key=None):
bin_range = (bin_range[0]-0.5, bin_range[1]+0.5)

element_type = Area if self.p.filled else Curve
data = data[np.isfinite(data)] if len(data) else []
data = data[isfinite(data)] if len(data) else []
if len(data) > 1:
try:
kde = stats.gaussian_kde(data)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/chart.py
Expand Up @@ -491,7 +491,7 @@ def _split_area(self, xs, lower, upper):
Splits area plots at nans and returns x- and y-coordinates for
each area separated by nans.
"""
split = np.where(np.isnan(xs) | np.isnan(lower) | np.isnan(upper))[0]
split = np.where(~isfinite(xs) | ~isfinite(lower) | ~isfinite(upper))[0]
xvals = np.split(xs, split)
lower = np.split(lower, split)
upper = np.split(upper, split)
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/bokeh/raster.py
@@ -1,7 +1,7 @@
import numpy as np
import param

from ...core.util import cartesian_product, dimension_sanitizer
from ...core.util import cartesian_product, dimension_sanitizer, isfinite
from ...element import Raster, RGB, HSV
from .element import ElementPlot, ColorbarPlot, line_properties, fill_properties
from .util import mpl_to_bokeh, colormesh, bokeh_version
Expand Down Expand Up @@ -168,7 +168,7 @@ def get_data(self, element, ranges, style):
xc, yc = [], []
for xs, ys, zval in zip(X, Y, zvals):
xs, ys = xs[:-1], ys[:-1]
if np.isfinite(zval) and all(np.isfinite(xs)) and all(np.isfinite(ys)):
if isfinite(zval) and all(isfinite(xs)) and all(isfinite(ys)):
XS.append(list(xs))
YS.append(list(ys))
mask.append(True)
Expand Down
8 changes: 4 additions & 4 deletions holoviews/plotting/bokeh/stats.py
Expand Up @@ -9,7 +9,7 @@
from ...core.dimension import Dimension
from ...core.ndmapping import sorted_context
from ...core.util import (basestring, dimension_sanitizer, wrap_tuple,
unique_iterator)
unique_iterator, isfinite)
from ...operation.stats import univariate_kde
from .chart import AreaPlot
from .element import (CompositeElementPlot, ColorbarPlot, LegendPlot,
Expand Down Expand Up @@ -171,7 +171,7 @@ def get_data(self, element, ranges, style):

# Compute statistics
vals = g.dimension_values(g.vdims[0])
vals = vals[np.isfinite(vals)]
vals = vals[isfinite(vals)]
if len(vals):
q1, q2, q3 = (np.percentile(vals, q=q)
for q in range(25, 100, 25))
Expand Down Expand Up @@ -321,7 +321,7 @@ def _kde_data(self, el, key, **kwargs):
el = el.clone(vdims=[vdim])
kde = univariate_kde(el, dimension=vdim, **kwargs)
xs, ys = (kde.dimension_values(i) for i in range(2))
mask = np.isfinite(ys) & (ys>0) # Mask out non-finite and zero values
mask = isfinite(ys) & (ys>0) # Mask out non-finite and zero values
xs, ys = xs[mask], ys[mask]
ys = (ys/ys.max())*(self.violin_width/2.) if len(ys) else []
ys = [key+(sign*y,) for sign, vs in ((-1, ys), (1, ys[::-1])) for y in vs]
Expand All @@ -330,7 +330,7 @@ def _kde_data(self, el, key, **kwargs):

bars, segments, scatter = defaultdict(list), defaultdict(list), {}
values = el.dimension_values(vdim)
values = values[np.isfinite(values)]
values = values[isfinite(values)]
if not len(values):
pass
elif self.inner == 'quartiles':
Expand Down
6 changes: 3 additions & 3 deletions holoviews/plotting/util.py
Expand Up @@ -14,7 +14,7 @@
from ..core.options import Cycle
from ..core.spaces import get_nested_streams
from ..core.util import (match_spec, wrap_tuple, basestring, get_overlay_spec,
unique_iterator, closest_match, is_number)
unique_iterator, closest_match, is_number, isfinite)
from ..streams import LinkedStream

def displayable(obj):
Expand Down Expand Up @@ -399,8 +399,8 @@ def get_sideplot_ranges(plot, element, main, ranges):

def within_range(range1, range2):
"""Checks whether range1 is within the range specified by range2."""
range1 = [r if np.isfinite(r) else None for r in range1]
range2 = [r if np.isfinite(r) else None for r in range2]
range1 = [r if isfinite(r) else None for r in range1]
range2 = [r if isfinite(r) else None for r in range2]
return ((range1[0] is None or range2[0] is None or range1[0] >= range2[0]) and
(range1[1] is None or range2[1] is None or range1[1] <= range2[1]))

Expand Down

0 comments on commit 646f97f

Please sign in to comment.