WestHealth / pyvis

Python package for creating and visualizing interactive network graphs.
http://pyvis.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
975 stars 165 forks source link

Empty AssertionError when using np.array #24

Closed ArthurAttout closed 5 years ago

ArthurAttout commented 5 years ago

When trying to create a network graph from Jupyter with np.array as input, an exception is thrown

arrayNodes = np.array([1,2,3,4])
g = Network(notebook=True)
g.add_nodes(np.array([1,2,3,4]))

throws


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-91-b8c17924b890> in <module>()
      1 arrayNodes = np.array([1,2,3,4])
      2 g = Network(notebook=True)
----> 3 g.add_nodes(np.array([1,2,3,4]))

C:\anaconda\lib\site-packages\pyvis\network.py in add_nodes(self, nodes, **kwargs)
    247 
    248         for node in nodes:
--> 249             assert isinstance(node, int) or isinstance(node, str)
    250             self.add_node(node, **nd[node])
    251 

AssertionError: 
boludo00 commented 5 years ago

When I first wrote that method I wanted to just enforce node values I knew the VisJS engine would not complain about, which explains the odd assertion. I think each value of the np array is something like a specifc numpy data type, that's why the assert fails.