Using `networkx.readwrite.json_graph.tree_data` does not preserve Graph attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 3.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 36
Description
When using networkx.readwrite.json_graph.tree_data to returns data in tree format that is suitable for JSON serialization and then convert this data back using networkx.readwrite.json_graph.tree_graph, you lose the Graph attributes.
Current Behaviour
For example the following is the current behaviour
>>> import networkx as nx
>>> from networkx.readwrite import json_graph
>>> DG = nx.DiGraph(page="some text")
>>> DG.add_node(5434)
>>> print(DG.graph)
{'page': 'some text'}
>>> data = json_graph.tree_data(DG, root=5434)
>>> DG = json_graph.tree_graph(data)
>>> print(DG.graph)
{}
Expected Behavior
I should get the following
>>> DG = json_graph.tree_graph(data)
>>> print(DG.graph)
{'page': 'some text'}
Environment
Python version: 2.10
NetworkX version: 2.6.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the networkx.readwrite.json_graph.tree_data and tree_graph entry points and reproduce the provided round-trip example. Add a regression test showing that graph attributes survive conversion, then run the relevant JSON graph tests and confirm the reconstructed graph retains {'page': 'some text'}.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100