Skip to content

Commit

Permalink
Merge branch 'master' of github.com:WestHealth/pyvis
Browse files Browse the repository at this point in the history
  • Loading branch information
Giancarlo Perrone committed Mar 8, 2019
2 parents 85f2b43 + e57c353 commit 18ddbfb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
12 changes: 9 additions & 3 deletions pyvis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,15 @@ def add_nodes(self, nodes, **kwargs):
nd[nodes[i]].update({k: v[i]})

for node in nodes:
assert isinstance(node, int) or isinstance(node, str)
self.add_node(node, **nd[node])

# check if node is `number-like`
try:
node = int(node)
self.add_node(node, **nd[node])
except:
# or node could be string
assert isinstance(node, str)
self.add_node(node, **nd[node])

def num_nodes(self):
"""
Return number of nodes
Expand Down
2 changes: 1 addition & 1 deletion pyvis/tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_add_edge_directed(self):
self.g.add_edge(0, 1)
self.assertTrue(self.g.edges)
for e in self.g.edges:
self.assertTrue(e["arrows"] == "from")
self.assertTrue(e["arrows"] == "to")


class UtilsTestCase(unittest.TestCase):
Expand Down
12 changes: 11 additions & 1 deletion pyvis/tests/test_me.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ..network import Network

import numpy as np

def test_canvas_size():
"""
Expand Down Expand Up @@ -68,3 +68,13 @@ def test_add_edge():
net.add_edge(0, 9)

assert(net.get_adj_list()[0] == set([2, 1, 3, 4, 5, 6, 7, 8, 9]))

def test_add_numpy_nodes():
"""
Test adding numpy array nodes since these
nodes will have specific numpy types
"""
arrayNodes = np.array([1,2,3,4])
g = Network()
g.add_nodes(np.array([1,2,3,4]))
assert g.get_nodes() == [1,2,3,4]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Jinja2==2.8
Jinja2==2.10
networkx==1.11
ipython==5.3.0

0 comments on commit 18ddbfb

Please sign in to comment.