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

DEP: Deprecate the all_triplets one-liner. #7060

Merged
merged 1 commit into from
Oct 31, 2023
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
4 changes: 4 additions & 0 deletions doc/developer/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ Version 3.4
in ``doc/reference/algorithms/trees.rst``
* Remove ``strongly_connected_components_recursive`` from
``algorithms/components/strongly_connected.py``

Version 3.5
~~~~~~~~~~~
* Remove ``all_triplets`` from ``algorithms/triads.py``
6 changes: 6 additions & 0 deletions networkx/algorithms/tests/test_triads.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import networkx as nx


def test_all_triplets_deprecated():
G = nx.DiGraph([(1, 2), (2, 3), (3, 4)])
with pytest.deprecated_call():
nx.all_triplets(G)


def test_triadic_census():
"""Tests the triadic_census function."""
G = nx.DiGraph()
Expand Down
17 changes: 17 additions & 0 deletions networkx/algorithms/triads.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ def is_triad(G):
def all_triplets(G):
"""Returns a generator of all possible sets of 3 nodes in a DiGraph.

.. deprecated:: 3.3

all_triplets is deprecated and will be removed in NetworkX version 3.5.
Use `itertools.combinations` instead::

all_triplets = itertools.combinations(G, 3)

Parameters
----------
G : digraph
Expand All @@ -328,6 +335,16 @@ def all_triplets(G):
[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]

"""
import warnings

warnings.warn(
(
"\n\nall_triplets is deprecated and will be rmoved in v3.5.\n"
"Use `itertools.combinations(G, 3)` instead."
),
category=DeprecationWarning,
stacklevel=4,
)
triplets = combinations(G.nodes(), 3)
return triplets

Expand Down
3 changes: 3 additions & 0 deletions networkx/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def set_warnings():
category=DeprecationWarning,
message="\n\nstrongly_connected_components_recursive",
)
warnings.filterwarnings(
"ignore", category=DeprecationWarning, message="\n\nall_triplets"
)


@pytest.fixture(autouse=True)
Expand Down