summaryrefslogtreecommitdiff
path: root/networkx/readwrite/json_graph
diff options
context:
space:
mode:
authorDilara Tekinoglu <dilaranurtuncturk@gmail.com>2022-06-15 22:45:31 +0300
committerGitHub <noreply@github.com>2022-06-15 22:45:31 +0300
commitc8a52b59c0e3975ebdab11c5cc1fe7cf3d1009b2 (patch)
tree49fa647c300cf1e13305aa1bc1f36601947149f9 /networkx/readwrite/json_graph
parent0a9384608ae3328951794a2583dd39b42b906dfc (diff)
downloadnetworkx-c8a52b59c0e3975ebdab11c5cc1fe7cf3d1009b2.tar.gz
Rm jit.py (#5751)
Co-authored-by: dtuncturk <dilaramemis@sabanciuniv.edu>
Diffstat (limited to 'networkx/readwrite/json_graph')
-rw-r--r--networkx/readwrite/json_graph/__init__.py1
-rw-r--r--networkx/readwrite/json_graph/jit.py118
-rw-r--r--networkx/readwrite/json_graph/tests/test_jit.py66
3 files changed, 0 insertions, 185 deletions
diff --git a/networkx/readwrite/json_graph/__init__.py b/networkx/readwrite/json_graph/__init__.py
index 7715fbba..2ee9d124 100644
--- a/networkx/readwrite/json_graph/__init__.py
+++ b/networkx/readwrite/json_graph/__init__.py
@@ -15,5 +15,4 @@ The three formats that you can generate with NetworkX are:
from networkx.readwrite.json_graph.node_link import *
from networkx.readwrite.json_graph.adjacency import *
from networkx.readwrite.json_graph.tree import *
-from networkx.readwrite.json_graph.jit import *
from networkx.readwrite.json_graph.cytoscape import *
diff --git a/networkx/readwrite/json_graph/jit.py b/networkx/readwrite/json_graph/jit.py
deleted file mode 100644
index 043f1a1f..00000000
--- a/networkx/readwrite/json_graph/jit.py
+++ /dev/null
@@ -1,118 +0,0 @@
-"""
-Read and write NetworkX graphs as JavaScript InfoVis Toolkit (JIT) format JSON.
-
-See the `JIT documentation`_ for more examples.
-
-Format
-------
-var json = [
- {
- "id": "aUniqueIdentifier",
- "name": "usually a nodes name",
- "data": {
- "some key": "some value",
- "some other key": "some other value"
- },
- "adjacencies": [
- {
- nodeTo:"aNodeId",
- data: {} //put whatever you want here
- },
- 'other adjacencies go here...'
- },
-
- 'other nodes go here...'
-];
-.. _JIT documentation: http://thejit.org
-"""
-
-import json
-import warnings
-
-import networkx as nx
-from networkx.utils.decorators import not_implemented_for
-
-__all__ = ["jit_graph", "jit_data"]
-
-
-def jit_graph(data, create_using=None):
- """Read a graph from JIT JSON.
-
- Parameters
- ----------
- data : JSON Graph Object
-
- create_using : Networkx Graph, optional (default: Graph())
- Return graph of this type. The provided instance will be cleared.
-
- Returns
- -------
- G : NetworkX Graph built from create_using if provided.
-
- .. deprecated:: 2.6
- """
- warnings.warn(
- ("jit_graph is deprecated and will be removed in NetworkX 3.0."),
- DeprecationWarning,
- )
-
- if create_using is None:
- G = nx.Graph()
- else:
- G = create_using
- G.clear()
-
- if isinstance(data, str):
- data = json.loads(data)
-
- for node in data:
- G.add_node(node["id"], **node["data"])
- if node.get("adjacencies") is not None:
- for adj in node["adjacencies"]:
- G.add_edge(node["id"], adj["nodeTo"], **adj["data"])
- return G
-
-
-@not_implemented_for("multigraph")
-def jit_data(G, indent=None, default=None):
- """Returns data in JIT JSON format.
-
- Parameters
- ----------
- G : NetworkX Graph
-
- indent: optional, default=None
- If indent is a non-negative integer, then JSON array elements and
- object members will be pretty-printed with that indent level.
- An indent level of 0, or negative, will only insert newlines.
- None (the default) selects the most compact representation.
-
- default: optional, default=None
- It will pass the value to the json.dumps function in order to
- be able to serialize custom objects used as nodes.
-
- Returns
- -------
- data: JIT JSON string
-
- .. deprecated:: 2.6
- """
- warnings.warn(
- ("jit_data is deprecated and will be removed in NetworkX 3.0."),
- DeprecationWarning,
- )
- json_graph = []
- for node in G.nodes():
- json_node = {"id": node, "name": node}
- # node data
- json_node["data"] = G.nodes[node]
- # adjacencies
- if G[node]:
- json_node["adjacencies"] = []
- for neighbour in G[node]:
- adjacency = {"nodeTo": neighbour}
- # adjacency data
- adjacency["data"] = G.edges[node, neighbour]
- json_node["adjacencies"].append(adjacency)
- json_graph.append(json_node)
- return json.dumps(json_graph, indent=indent, default=default)
diff --git a/networkx/readwrite/json_graph/tests/test_jit.py b/networkx/readwrite/json_graph/tests/test_jit.py
deleted file mode 100644
index 309c4055..00000000
--- a/networkx/readwrite/json_graph/tests/test_jit.py
+++ /dev/null
@@ -1,66 +0,0 @@
-import json
-
-import pytest
-
-import networkx as nx
-from networkx.readwrite.json_graph import jit_data, jit_graph
-
-
-class TestJIT:
- def test_jit(self):
- G = nx.Graph()
- G.add_node("Node1", node_data="foobar")
- G.add_node("Node3", node_data="bar")
- G.add_node("Node4")
- G.add_edge("Node1", "Node2", weight=9, something="isSomething")
- G.add_edge("Node2", "Node3", weight=4, something="isNotSomething")
- G.add_edge("Node1", "Node2")
- d = jit_data(G)
- K = jit_graph(json.loads(d))
- assert nx.is_isomorphic(G, K)
-
- def test_jit_2(self):
- G = nx.Graph()
- G.add_node(1, node_data=3)
- G.add_node(3, node_data=0)
- G.add_edge(1, 2, weight=9, something=0)
- G.add_edge(2, 3, weight=4, something=3)
- G.add_edge(1, 2)
- d = jit_data(G)
- K = jit_graph(json.loads(d))
- assert nx.is_isomorphic(G, K)
-
- def test_jit_directed(self):
- G = nx.DiGraph()
- G.add_node(1, node_data=3)
- G.add_node(3, node_data=0)
- G.add_edge(1, 2, weight=9, something=0)
- G.add_edge(2, 3, weight=4, something=3)
- G.add_edge(1, 2)
- d = jit_data(G)
- K = jit_graph(json.loads(d), create_using=nx.DiGraph())
- assert nx.is_isomorphic(G, K)
-
- def test_jit_multi_directed(self):
- G = nx.MultiDiGraph()
- G.add_node(1, node_data=3)
- G.add_node(3, node_data=0)
- G.add_edge(1, 2, weight=9, something=0)
- G.add_edge(2, 3, weight=4, something=3)
- G.add_edge(1, 2)
- pytest.raises(nx.NetworkXNotImplemented, jit_data, G)
-
- H = nx.DiGraph(G)
- d = jit_data(H)
- K = jit_graph(json.loads(d), create_using=nx.MultiDiGraph())
- assert nx.is_isomorphic(H, K)
- K.add_edge(1, 2)
- assert not nx.is_isomorphic(H, K)
- assert nx.is_isomorphic(G, K)
-
- def test_jit_round_trip(self):
- G = nx.Graph()
- d = nx.jit_data(G)
- H = jit_graph(json.loads(d))
- K = jit_graph(d)
- assert nx.is_isomorphic(H, K)