Skip to content

Commit

Permalink
Fixed empty data issues with multiinterface
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 23, 2017
1 parent 47a776d commit a0ce9bb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
6 changes: 6 additions & 0 deletions holoviews/core/data/multipath.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def isscalar(cls, dataset, dim):
"""
Tests if dimension is scalar in each subpath.
"""
if not dataset.data:
return True
ds = cls._inner_dataset_template(dataset)
isscalar = []
for d in dataset.data:
Expand All @@ -117,6 +119,8 @@ def select(cls, dataset, selection_mask=None, **selection):
"""
Applies selectiong on all the subpaths.
"""
if not self.dataset.data:
return []
ds = cls._inner_dataset_template(dataset)
data = []
for d in dataset.data:
Expand Down Expand Up @@ -232,6 +236,8 @@ def split(cls, dataset, start, end, datatype, **kwargs):
for d in dataset.data[start: end]:
objs.append(dataset.clone(d, datatype=cls.subtypes))
return objs
elif not dataset.data:
return objs
ds = cls._inner_dataset_template(dataset)
for d in dataset.data:
ds.data = d
Expand Down
28 changes: 28 additions & 0 deletions tests/testmultiinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,39 @@ def test_multi_array_length(self):
mds = Path(arrays, kdims=['x', 'y'], datatype=['multitabular'])
self.assertEqual(len(mds), 5)

def test_multi_empty_length(self):
mds = Path([], kdims=['x', 'y'], datatype=['multitabular'])
self.assertEqual(len(mds), 0)

def test_multi_array_range(self):
arrays = [np.column_stack([np.arange(i, i+2), np.arange(i, i+2)]) for i in range(2)]
mds = Path(arrays, kdims=['x', 'y'], datatype=['multitabular'])
self.assertEqual(mds.range(0), (0, 2))

def test_multi_empty_range(self):
mds = Path([], kdims=['x', 'y'], datatype=['multitabular'])
low, high = mds.range(0)
self.assertFalse(np.isfinite(np.NaN))
self.assertFalse(np.isfinite(np.NaN))

def test_multi_array_shape(self):
arrays = [np.column_stack([np.arange(i, i+2), np.arange(i, i+2)]) for i in range(2)]
mds = Path(arrays, kdims=['x', 'y'], datatype=['multitabular'])
self.assertEqual(mds.shape, (5, 2))

def test_multi_empty_shape(self):
mds = Path([], kdims=['x', 'y'], datatype=['multitabular'])
self.assertEqual(mds.shape, (0, 2))

def test_multi_array_values(self):
arrays = [np.column_stack([np.arange(i, i+2), np.arange(i, i+2)]) for i in range(2)]
mds = Path(arrays, kdims=['x', 'y'], datatype=['multitabular'])
self.assertEqual(mds.dimension_values(0), np.array([0., 1, np.NaN, 1, 2]))

def test_multi_empty_array_values(self):
mds = Path([], kdims=['x', 'y'], datatype=['multitabular'])
self.assertEqual(mds.dimension_values(0), np.array([]))

def test_multi_array_values_coordinates_nonexpanded(self):
arrays = [np.column_stack([np.arange(i, i+2), np.arange(i, i+2)]) for i in range(2)]
mds = Path(arrays, kdims=['x', 'y'], datatype=['multitabular'])
Expand Down Expand Up @@ -104,3 +122,13 @@ def test_multi_mixed_dims_raises(self):
error = "Following dimensions not found in data: \['y'\]"
with self.assertRaisesRegexp(ValueError, error):
mds = Path(arrays, kdims=['x', 'y'], datatype=['multitabular'])

def test_multi_split(self):
arrays = [np.column_stack([np.arange(i, i+2), np.arange(i, i+2)]) for i in range(2)]
mds = Path(arrays, kdims=['x', 'y'], datatype=['multitabular'])
for arr1, arr2 in zip(mds.split(datatype='array'), arrays):
self.assertEqual(arr1, arr2)

def test_multi_split_empty(self):
mds = Path([], kdims=['x', 'y'], datatype=['multitabular'])
self.assertEqual(len(mds.split()), 0)
26 changes: 25 additions & 1 deletion tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from holoviews.element import (Curve, Scatter, Image, VLine, Points,
HeatMap, QuadMesh, Spikes, ErrorBars,
Scatter3D, Path, Polygons, Bars, Text,
BoxWhisker, HLine, RGB, Raster)
BoxWhisker, HLine, RGB, Raster, Contours)
from holoviews.element.comparison import ComparisonTestCase
from holoviews.streams import Stream, PointerXY, PointerX
from holoviews.operation import gridmatrix
Expand Down Expand Up @@ -873,6 +873,30 @@ def test_empty_spikes_plot(self):
self.assertEqual(len(source.data['xs']), 0)
self.assertEqual(len(source.data['ys']), 0)

def test_empty_path_plot(self):
path = Path([], vdims=['Intensity']).opts(plot=dict(color_index=2))
plot = bokeh_renderer.get_plot(path)
source = plot.handles['source']
self.assertEqual(len(source.data['xs']), 0)
self.assertEqual(len(source.data['ys']), 0)
self.assertEqual(len(source.data['Intensity']), 0)

def test_empty_contours_plot(self):
contours = Contours([], vdims=['Intensity'])
plot = bokeh_renderer.get_plot(contours)
source = plot.handles['source']
self.assertEqual(len(source.data['xs']), 0)
self.assertEqual(len(source.data['ys']), 0)
self.assertEqual(len(source.data['Intensity']), 0)

def test_empty_polygons_plot(self):
poly = Polygons([], vdims=['Intensity'])
plot = bokeh_renderer.get_plot(poly)
source = plot.handles['source']
self.assertEqual(len(source.data['xs']), 0)
self.assertEqual(len(source.data['ys']), 0)
self.assertEqual(len(source.data['Intensity']), 0)

def test_side_histogram_no_cmapper(self):
points = Points(np.random.rand(100, 2))
plot = bokeh_renderer.get_plot(points.hist())
Expand Down

0 comments on commit a0ce9bb

Please sign in to comment.