diff options
| author | Dan Schult <dschult@colgate.edu> | 2022-06-16 05:44:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-16 12:44:24 +0300 |
| commit | 066ade5d2de8ba564366cc8055899d6b559aff56 (patch) | |
| tree | ae68a95d3e2933f93f97f5c20312443590bc5b49 /networkx/readwrite/json_graph | |
| parent | 4a64babe60af86fc7e194ae4740592bd9ef4f0c6 (diff) | |
| download | networkx-066ade5d2de8ba564366cc8055899d6b559aff56.tar.gz | |
update cytoscape functions to drop old signature (#5784)
update cytoscape functions with new signature
Diffstat (limited to 'networkx/readwrite/json_graph')
| -rw-r--r-- | networkx/readwrite/json_graph/cytoscape.py | 73 | ||||
| -rw-r--r-- | networkx/readwrite/json_graph/tests/test_cytoscape.py | 17 |
2 files changed, 2 insertions, 88 deletions
diff --git a/networkx/readwrite/json_graph/cytoscape.py b/networkx/readwrite/json_graph/cytoscape.py index 296242c3..c0c0e3f3 100644 --- a/networkx/readwrite/json_graph/cytoscape.py +++ b/networkx/readwrite/json_graph/cytoscape.py @@ -3,24 +3,13 @@ import networkx as nx __all__ = ["cytoscape_data", "cytoscape_graph"] -def cytoscape_data(G, attrs=None, name="name", ident="id"): +def cytoscape_data(G, name="name", ident="id"): """Returns data in Cytoscape JSON format (cyjs). Parameters ---------- G : NetworkX Graph The graph to convert to cytoscape format - attrs : dict or None (default=None) - A dictionary containing the keys 'name' and 'ident' which are mapped to - the 'name' and 'id' node elements in cyjs format. All other keys are - ignored. Default is `None` which results in the default mapping - ``dict(name="name", ident="id")``. - - .. deprecated:: 2.6 - - The `attrs` keyword argument will be replaced with `name` and - `ident` in networkx 3.0 - name : string A string which is mapped to the 'name' node element in cyjs format. Must not have the same value as `ident`. @@ -58,30 +47,6 @@ def cytoscape_data(G, attrs=None, name="name", ident="id"): {'data': {'id': '1', 'value': 1, 'name': '1'}}], 'edges': [{'data': {'source': 0, 'target': 1}}]}} """ - # ------ TODO: Remove between the lines in 3.0 ----- # - if attrs is not None: - import warnings - - msg = ( - "\nThe `attrs` keyword argument of cytoscape_data is deprecated\n" - "and will be removed in networkx 3.0.\n" - "It is replaced with explicit `name` and `ident` keyword\n" - "arguments.\n" - "To make this warning go away and ensure usage is forward\n" - "compatible, replace `attrs` with `name` and `ident`,\n" - "for example:\n\n" - " >>> cytoscape_data(G, attrs={'name': 'foo', 'ident': 'bar'})\n\n" - "should instead be written as\n\n" - " >>> cytoscape_data(G, name='foo', ident='bar')\n\n" - "in networkx 3.0.\n" - "The default values of 'name' and 'id' will not change." - ) - warnings.warn(msg, DeprecationWarning, stacklevel=2) - - name = attrs["name"] - ident = attrs["ident"] - # -------------------------------------------------- # - if name == ident: raise nx.NetworkXError("name and ident must be different.") @@ -115,7 +80,7 @@ def cytoscape_data(G, attrs=None, name="name", ident="id"): return jsondata -def cytoscape_graph(data, attrs=None, name="name", ident="id"): +def cytoscape_graph(data, name="name", ident="id"): """ Create a NetworkX graph from a dictionary in cytoscape JSON format. @@ -123,17 +88,6 @@ def cytoscape_graph(data, attrs=None, name="name", ident="id"): ---------- data : dict A dictionary of data conforming to cytoscape JSON format. - attrs : dict or None (default=None) - A dictionary containing the keys 'name' and 'ident' which are mapped to - the 'name' and 'id' node elements in cyjs format. All other keys are - ignored. Default is `None` which results in the default mapping - ``dict(name="name", ident="id")``. - - .. deprecated:: 2.6 - - The `attrs` keyword argument will be replaced with `name` and - `ident` in networkx 3.0 - name : string A string which is mapped to the 'name' node element in cyjs format. Must not have the same value as `ident`. @@ -181,29 +135,6 @@ def cytoscape_graph(data, attrs=None, name="name", ident="id"): >>> G.edges(data=True) EdgeDataView([(0, 1, {'source': 0, 'target': 1})]) """ - # ------ TODO: Remove between the lines in 3.0 ----- # - if attrs is not None: - import warnings - - msg = ( - "\nThe `attrs` keyword argument of cytoscape_data is deprecated\n" - "and will be removed in networkx 3.0.\n" - "It is replaced with explicit `name` and `ident` keyword\n" - "arguments.\n" - "To make this warning go away and ensure usage is forward\n" - "compatible, replace `attrs` with `name` and `ident`,\n" - "for example:\n\n" - " >>> cytoscape_data(G, attrs={'name': 'foo', 'ident': 'bar'})\n\n" - "should instead be written as\n\n" - " >>> cytoscape_data(G, name='foo', ident='bar')\n\n" - "The default values of 'name' and 'id' will not change." - ) - warnings.warn(msg, DeprecationWarning, stacklevel=2) - - name = attrs["name"] - ident = attrs["ident"] - # -------------------------------------------------- # - if name == ident: raise nx.NetworkXError("name and ident must be different.") diff --git a/networkx/readwrite/json_graph/tests/test_cytoscape.py b/networkx/readwrite/json_graph/tests/test_cytoscape.py index cdb101f9..a5990ffc 100644 --- a/networkx/readwrite/json_graph/tests/test_cytoscape.py +++ b/networkx/readwrite/json_graph/tests/test_cytoscape.py @@ -7,23 +7,6 @@ import networkx as nx from networkx.readwrite.json_graph import cytoscape_data, cytoscape_graph -# TODO: To be removed when signature change complete in 3.0 -def test_attrs_deprecation(recwarn): - G = nx.path_graph(3) - - # No warnings when `attrs` kwarg not used - data = cytoscape_data(G) - H = cytoscape_graph(data) - assert len(recwarn) == 0 - - # Future warning raised with `attrs` kwarg - attrs = {"name": "foo", "ident": "bar"} - with pytest.warns(DeprecationWarning): - data = cytoscape_data(G, attrs) - with pytest.warns(DeprecationWarning): - H = cytoscape_graph(data, attrs) - - def test_graph(): G = nx.path_graph(4) H = cytoscape_graph(cytoscape_data(G)) |
