Skip to content

Commit

Permalink
Merge fb87324 into 7c06dbd
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 18, 2017
2 parents 7c06dbd + fb87324 commit 45268a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions holoviews/element/graphs.py
Expand Up @@ -424,8 +424,10 @@ def __init__(self, data, kdims=None, vdims=None, **params):
edges, nodes, edgepaths = data
else:
edges, nodes, edgepaths = data, None, None

super(TriMesh, self).__init__(edges, kdims=kdims, vdims=vdims, **params)
if nodes is None:
if isinstance(edges, list) and len(edges) == 0:
if len(self) == 0:
nodes = []
else:
raise ValueError("TriMesh expects both simplices and nodes "
Expand All @@ -452,7 +454,7 @@ def __init__(self, data, kdims=None, vdims=None, **params):
"x/y positions and optionally the node indices.")
if edgepaths is not None and not isinstance(edgepaths, self._edge_type):
edgepaths = self._edge_type(edgepaths)
super(TriMesh, self).__init__(edges, kdims=kdims, vdims=vdims, **params)

self._nodes = nodes
self._edgepaths = edgepaths

Expand Down
10 changes: 10 additions & 0 deletions tests/testgraphelement.py
Expand Up @@ -138,6 +138,16 @@ def test_trimesh_constructor(self):
self.assertEqual(trimesh.array(), np.array(self.simplices))
self.assertEqual(trimesh.nodes.array(), np.array(self.nodes))

def test_trimesh_empty(self):
trimesh = TriMesh([])
self.assertEqual(trimesh.array(), np.empty((0, 3)))
self.assertEqual(trimesh.nodes.array(), np.empty((0, 3)))

def test_trimesh_empty_clone(self):
trimesh = TriMesh([]).clone()
self.assertEqual(trimesh.array(), np.empty((0, 3)))
self.assertEqual(trimesh.nodes.array(), np.empty((0, 3)))

def test_trimesh_constructor_tuple_nodes(self):
nodes = tuple(zip(*self.nodes))[:2]
trimesh = TriMesh((self.simplices, nodes))
Expand Down

0 comments on commit 45268a0

Please sign in to comment.