question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: Can't clean for JSON for networkx nodes that are objects.

See original GitHub issue

Execute the following in a jupyter lab notebook and you’ll get ‘ValueError: Can’t clean for JSON’. I believe this should work, and is a bug. It works fine if I use nx.draw(G) instead of ipycytoscape.

import ipycytoscape
import networkx as nx

class Node:
    def __init__(self, name):
        self.name = name

n1 = Node("node 1")
n2 = Node("node 2")
        
G = nx.Graph()

G.add_node(n1)
G.add_node(n2)

G.add_edge(n1, n2)

undirected = ipycytoscape.CytoscapeWidget()
undirected.graph.add_graph_from_networkx(G)
undirected

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
MridulScommented, Jul 8, 2020

Is there any specific use case for having custom classes? (unless the idea here is to mirror exactly nx.draw). The str() argument will make it work with ipycytoscape but we will essentially lose all the information of the object. (which should be okay if we want to make ipycytoscape compatible with hashable node objects).

If the idea here is to pass information from the Node custom object to the ipycytoscape graph object then we can do something like

import ipycytoscape

class CustomNode(ipycytoscape.Node):
    def __init__(self, i, test):
        super().__init__()
        self.data['id'] = i
        self.data['test_var'] = test

ipyGraph = ipycytoscape.CytoscapeWidget()
ipyGraph.graph.add_node(CustomNode(1, 'boo'))

and we can access the newly created custom nodes by something like

>>> ipyGraph.graph.nodes
[CustomNode(data={'id': 1, 'test_var': 'boo'}, position={})]
0reactions
jaydonnellcommented, Jul 9, 2020

gotcha, sorry, I missed the call to str() in your’s the first time i looked at it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jupyter Lab ValueError: Can't clean for JSON - Plotly Python
Really new to the Jupyter/Pandas/Plotly ecosystem. Successfully reading in dataframes and calculating some new columns with success.
Read more >
NetworkX Reference
NetworkX is a Python language software package for the creation, manipulation, and study of the structure, dynamics,.
Read more >
Method to save networkx graph to json graph? - Stack Overflow
Show activity on this post. Seems like there should be a method in networkx to export the json graph format, but I don't...
Read more >
NetworkX Reference - Read the Docs
NetworkX is a Python language software package for the creation, manipulation, and study of the structure, dynamics,.
Read more >
OSMnx: Python for Street Networks - Geoff Boeing
OpenStreetMap nodes can be weird: they include intersections, ... how could I load back the saved shapefile into a networkx graph object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found