Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Object of type 'int64' is not JSON serializable #7

Open
j6k4m8 opened this issue Mar 3, 2018 · 2 comments
Open

TypeError: Object of type 'int64' is not JSON serializable #7

j6k4m8 opened this issue Mar 3, 2018 · 2 comments

Comments

@j6k4m8
Copy link

j6k4m8 commented Mar 3, 2018

When you try to render a graph derived from a numpy adjacency matrix, you get this error.

G = nx.from_numpy_matrix(mymatrix)
nx2d3.embed_networkx(G)

This can be solved by converting node IDs to strings (G = nx.relabel_nodes(G, lambda x: str(x))) but it seems like a more general solution is to handle this in the embed_networkx call, since any non-JSON-serializable ID type will fail with this error.

(Traceback suggests that this is a failure of the node_link_data(graph) call on line 99 of embed.py)

[EDIT]: This still fails even if I verify that the data are JSON-serializable with

G =  json_graph.node_link_graph(json_graph.node_link_data(G))

So this is a function of the nx2d3 library, not of the networkx JSON serializer, I believe.

@cthoyt
Copy link
Owner

cthoyt commented Nov 21, 2018

First, sorry for the late reply.

Could you give an example of a real matrix for which this is a problem?

Also, do you think that it's a good idea to try and bake more logic into the embed_networkx function? There could be lots of edge cases. A previous pull request added the ability to specify a JSONEncoder that can be made custom for any kinds of classes, so that might be able to fit more general needs without having to write more code in this library.

@j6k4m8
Copy link
Author

j6k4m8 commented Nov 23, 2018

My main concern here is that the serialization error appears to be internal to nx2d3 rather than an issue with the data; using the python standard json library for serialization seems to work.

Definitely agree about not bloating this library though! Maybe a good middle ground is to throw a more readable error if serialization fails (for this or any other reason)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants