Skip to content

Commit

Permalink
LabelledData.map drops None values returned by map function (#1685)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Jul 6, 2017
1 parent 16fd205 commit 0c057fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion holoviews/core/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,9 @@ def map(self, map_fn, specs=None, clone=True):
if self._deep_indexable:
deep_mapped = self.clone(shared_data=False) if clone else self
for k, v in self.items():
deep_mapped[k] = v.map(map_fn, specs, clone)
new_val = v.map(map_fn, specs, clone)
if new_val is not None:
deep_mapped[k] = new_val
if applies: deep_mapped = map_fn(deep_mapped)
return deep_mapped
else:
Expand Down
7 changes: 7 additions & 0 deletions tests/testndmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,10 @@ def test_columns_collapse_heterogeneous(self):
def test_columns_sample_homogeneous(self):
samples = self.columns.sample([0, 5, 10]).dimension_values('y')
self.assertEqual(samples, np.array([0, 10, 20]))

def test_holomap_map_with_none(self):
hmap = HoloMap({i: Dataset({'x':self.xs, 'y': self.ys * i},
kdims=['x'], vdims=['y'])
for i in range(10)}, kdims=['z'])
mapped = hmap.map(lambda x: x if x.range(1)[1] > 0 else None, Dataset)
self.assertEqual(hmap[1:10], mapped)

0 comments on commit 0c057fb

Please sign in to comment.