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

Deprecate the create argument of nonisomorphic_trees #7316

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/developer/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ Version 3.5
to return a dict. See #6527
* Change ``shortest_path`` in ``algorithms/shortest_path/generic.py``
to return a iterator. See #6527
* Remove ``create`` keyword argument from ``nonisomorphic_trees`` in
``generators/nonisomorphic_trees``.
3 changes: 3 additions & 0 deletions networkx/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def set_warnings():
warnings.filterwarnings(
"ignore", category=DeprecationWarning, message="\n\nk_corona"
)
warnings.filterwarnings(
"ignore", category=DeprecationWarning, message=r"\n\nThe 'create=matrix'"
)


@pytest.fixture(autouse=True)
Expand Down
23 changes: 23 additions & 0 deletions networkx/generators/nonisomorphic_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ def nonisomorphic_trees(order, create="graph"):
If ``"graph"`` is selected a list of ``Graph`` instances will be returned,
if matrix is selected a list of adjacency matrices will be returned.

.. deprecated:: 3.3

The `create` argument is deprecated and will be removed in NetworkX
version 3.5. In the future, `nonisomorphic_trees` will yield graph
instances by default. To generate adjacency matrices, call
``nx.to_numpy_array`` on the output, e.g.::

[nx.to_numpy_array(G) for G in nx.nonisomorphic_trees(N)]

Yields
------
list
Expand All @@ -45,6 +54,20 @@ def nonisomorphic_trees(order, create="graph"):
if create == "graph":
yield _layout_to_graph(layout)
elif create == "matrix":
import warnings

warnings.warn(
(
"\n\nThe 'create=matrix' argument of nonisomorphic_trees\n"
"is deprecated and will be removed in version 3.5.\n"
"Use ``nx.to_numpy_array`` to convert graphs to adjacency "
"matrices, e.g.::\n\n"
" [nx.to_numpy_array(G) for G in nx.nonisomorphic_trees(N)]"
),
category=DeprecationWarning,
stacklevel=2,
)

yield _layout_to_matrix(layout)
layout = _next_rooted_tree(layout)

Expand Down
17 changes: 10 additions & 7 deletions networkx/generators/tests/test_nonisomorphic_trees.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""
====================
Generators - Non Isomorphic Trees
====================

Unit tests for WROM algorithm generator in generators/nonisomorphic_trees.py
"""
import pytest

import networkx as nx
from networkx.utils import edges_equal

Expand Down Expand Up @@ -54,11 +52,16 @@ def f(x):

def test_nonisomorphic_trees_matrix(self):
trees_2 = [[[0, 1], [1, 0]]]
assert list(nx.nonisomorphic_trees(2, create="matrix")) == trees_2
with pytest.deprecated_call():
assert list(nx.nonisomorphic_trees(2, create="matrix")) == trees_2

trees_3 = [[[0, 1, 1], [1, 0, 0], [1, 0, 0]]]
assert list(nx.nonisomorphic_trees(3, create="matrix")) == trees_3
with pytest.deprecated_call():
assert list(nx.nonisomorphic_trees(3, create="matrix")) == trees_3

trees_4 = [
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]],
[[0, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]],
]
assert list(nx.nonisomorphic_trees(4, create="matrix")) == trees_4
with pytest.deprecated_call():
assert list(nx.nonisomorphic_trees(4, create="matrix")) == trees_4