Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into forceatlas2-networkx
Browse files Browse the repository at this point in the history
  • Loading branch information
cvanelteren committed Jun 20, 2024
2 parents 05e0218 + 5f35e30 commit 638051a
Show file tree
Hide file tree
Showing 26 changed files with 252 additions and 157 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/circleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Run CircleCI image artifact redirector
steps:
- name: GitHub Action step
uses: larsoner/circleci-artifacts-redirector-action@master
uses: scientific-python/circleci-artifacts-redirector-action@4e13a10d89177f4bfc8007a7064bdbeda848d8d1 # v1.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
api-token: ${{ secrets.CIRCLECI_ARTIFACT_REDIRECTOR_TOKEN }}
Expand All @@ -19,7 +19,7 @@ jobs:
name: Run CircleCI documentation artifact redirector
steps:
- name: GitHub Action step
uses: larsoner/circleci-artifacts-redirector-action@master
uses: scientific-python/circleci-artifacts-redirector-action@4e13a10d89177f4bfc8007a7064bdbeda848d8d1 # v1.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
api-token: ${{ secrets.CIRCLECI_ARTIFACT_REDIRECTOR_TOKEN }}
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
attestations: write
contents: read
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -30,5 +32,13 @@ jobs:
pip install -U build twine wheel
python -m build --sdist --wheel
- name: Verify the distribution
run: twine check --strict dist/*

- name: Generate artifact attestation for sdist and wheel
uses: actions/attest-build-provenance@173725a1209d09b31f9d30a3890cf2757ebbff0d # v1.1.2
with:
subject-path: "dist/networkx-*"

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ networkx.egg-info/
.pytest_cache

# Virtual environment directory
networkx-dev/
networkx-dev/

# Benchmark products
benchmarks/env
benchmarks/results
30 changes: 17 additions & 13 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from datetime import date
from sphinx_gallery.sorting import ExplicitOrder, FileNameSortKey
from intersphinx_registry import get_intersphinx_mapping
from warnings import filterwarnings

filterwarnings(
Expand Down Expand Up @@ -228,19 +229,22 @@
latex_appendices = ["tutorial"]

# Intersphinx mapping
intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"neps": ("https://numpy.org/neps/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"geopandas": ("https://geopandas.org/en/stable/", None),
"pygraphviz": ("https://pygraphviz.github.io/documentation/stable/", None),
"sphinx-gallery": ("https://sphinx-gallery.github.io/stable/", None),
"nx-guides": ("https://networkx.org/nx-guides/", None),
"sympy": ("https://docs.sympy.org/latest/", None),
}

intersphinx_mapping = get_intersphinx_mapping(
packages={
"python",
"numpy",
"neps",
"matplotlib",
"scipy",
"pandas",
"geopandas",
"pygraphviz",
"sphinx-gallery",
"sympy",
"nx-guides",
}
)

# The reST default role (used for this markup: `text`) to use for all
# documents.
Expand Down
12 changes: 6 additions & 6 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ To cite NetworkX please use the following publication:

Aric A. Hagberg, Daniel A. Schult and Pieter J. Swart,
`"Exploring network structure, dynamics, and function using NetworkX"
<https://conference.scipy.org/proceedings/SciPy2008/paper_2/>`_,
<http://conference.scipy.org.s3-website-us-east-1.amazonaws.com/proceedings/scipy2008/paper_2/>`_,
in
`Proceedings of the 7th Python in Science Conference (SciPy2008)
<https://conference.scipy.org/proceedings/SciPy2008/index.html>`_, Gäel
Varoquaux, Travis Vaught, and Jarrod Millman (Eds), (Pasadena, CA
USA), pp. 11--15, Aug 2008
<http://conference.scipy.org.s3-website-us-east-1.amazonaws.com/proceedings/scipy2008/index.html>`_,
Gäel Varoquaux, Travis Vaught, and Jarrod Millman (Eds),
(Pasadena, CA USA), pp. 11--15, Aug 2008

.. only:: html

`PDF <https://conference.scipy.org/proceedings/SciPy2008/paper_2/full_text.pdf>`_
`BibTeX <https://conference.scipy.org/proceedings/SciPy2008/paper_2/reference.bib>`_
`PDF <http://conference.scipy.org.s3-website-us-east-1.amazonaws.com/proceedings/scipy2008/paper_2/full_text.pdf>`_
`BibTeX <http://conference.scipy.org.s3-website-us-east-1.amazonaws.com/proceedings/scipy2008/paper_2/reference.bib>`_

Audience
--------
Expand Down
30 changes: 19 additions & 11 deletions networkx/algorithms/assortativity/pairs.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
"""Generators of x-y pairs of node data."""
"""Generators of x-y pairs of node data."""
import networkx as nx

__all__ = ["node_attribute_xy", "node_degree_xy"]


@nx._dispatchable(node_attrs="attribute")
def node_attribute_xy(G, attribute, nodes=None):
"""Returns iterator of node-attribute pairs for all edges in G.
"""Yields 2-tuples of node attribute values for all edges in `G`.
This generator yields, for each edge in `G` incident to a node in `nodes`,
a 2-tuple of form ``(attribute value, attribute value)`` for the parameter
specified node-attribute.
Parameters
----------
G: NetworkX graph
attribute: key
The node attribute key.
The node attribute key.
nodes: list or iterable (optional)
Use only edges that are incident to specified nodes.
The default is all nodes.
Returns
-------
Yields
------
(x, y): 2-tuple
Generates 2-tuple of (attribute, attribute) values.
Expand All @@ -29,13 +33,14 @@ def node_attribute_xy(G, attribute, nodes=None):
>>> G = nx.DiGraph()
>>> G.add_node(1, color="red")
>>> G.add_node(2, color="blue")
>>> G.add_node(3, color="green")
>>> G.add_edge(1, 2)
>>> list(nx.node_attribute_xy(G, "color"))
[('red', 'blue')]
Notes
-----
For undirected graphs each edge is produced twice, once for each edge
For undirected graphs, each edge is produced twice, once for each edge
representation (u, v) and (v, u), with the exception of self-loop edges
which only appear once.
"""
Expand All @@ -61,7 +66,11 @@ def node_attribute_xy(G, attribute, nodes=None):

@nx._dispatchable(edge_attrs="weight")
def node_degree_xy(G, x="out", y="in", weight=None, nodes=None):
"""Generate node degree-degree pairs for edges in G.
"""Yields 2-tuples of ``(degree, degree)`` values for edges in `G`.
This generator yields, for each edge in `G` incident to a node in `nodes`,
a 2-tuple of form ``(degree, degree)``. The node degrees are weighted
when a `weight` attribute is specified.
Parameters
----------
Expand All @@ -82,12 +91,11 @@ def node_degree_xy(G, x="out", y="in", weight=None, nodes=None):
Use only edges that are adjacency to specified nodes.
The default is all nodes.
Returns
-------
Yields
------
(x, y): 2-tuple
Generates 2-tuple of (degree, degree) values.
Examples
--------
>>> G = nx.DiGraph()
Expand All @@ -99,7 +107,7 @@ def node_degree_xy(G, x="out", y="in", weight=None, nodes=None):
Notes
-----
For undirected graphs each edge is produced twice, once for each edge
For undirected graphs, each edge is produced twice, once for each edge
representation (u, v) and (v, u), with the exception of self-loop edges
which only appear once.
"""
Expand Down
1 change: 0 additions & 1 deletion networkx/algorithms/bridges.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def bridges(G, root=None):
H = nx.Graph(G) if multigraph else G
chains = nx.chain_decomposition(H, root=root)
chain_edges = set(chain.from_iterable(chains))
H_copy = H.copy()
if root is not None:
H = H.subgraph(nx.node_connected_component(H, root)).copy()
for u, v in H.edges():
Expand Down
2 changes: 1 addition & 1 deletion networkx/algorithms/link_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def common_neighbor_centrality(G, ebunch=None, alpha=0.8):
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
If self loops exsists in `ebunch` or in `G` (if `ebunch` is `None`).
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
If `ebunch` has a node that is not in `G`.
Expand Down
4 changes: 2 additions & 2 deletions networkx/algorithms/polynomials.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
>>> import sympy
>>> x = sympy.Symbol("x")
>>> G = nx.complete_graph(4)
>>> A = nx.adjacency_matrix(G)
>>> M = sympy.SparseMatrix(A.todense())
>>> A = nx.to_numpy_array(G, dtype=int)
>>> M = sympy.SparseMatrix(A)
>>> M.charpoly(x).as_expr()
x**4 - 6*x**2 - 8*x - 3
Expand Down
2 changes: 1 addition & 1 deletion networkx/algorithms/shortest_paths/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def shortest_path_length(G, source=None, target=None, weight=None, method="dijks
Returns
-------
length: int or iterator
length: number or iterator
If the source and target are both specified, return the length of
the shortest path from the source to the target.
Expand Down
29 changes: 23 additions & 6 deletions networkx/classes/digraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class _CachedPropertyResetterAdjAndSucc:
are set to new objects. In addition, the attributes `_succ` and `_adj`
are synced so these two names point to the same object.
Warning: most of the time, when ``G._adj`` is set, ``G._pred`` should also
be set to maintain a valid data structure. They share datadicts.
This object sits on a class and ensures that any instance of that
class clears its cached properties "succ" and "adj" whenever the
underlying instance attributes "_succ" or "_adj" are set to a new object.
Expand All @@ -39,10 +42,18 @@ def __set__(self, obj, value):
od["_adj"] = value
od["_succ"] = value
# reset cached properties
if "adj" in od:
del od["adj"]
if "succ" in od:
del od["succ"]
props = [
"adj",
"succ",
"edges",
"out_edges",
"degree",
"out_degree",
"in_degree",
]
for prop in props:
if prop in od:
del od[prop]


class _CachedPropertyResetterPred:
Expand All @@ -51,6 +62,9 @@ class _CachedPropertyResetterPred:
This assumes that the ``cached_property`` ``G.pred`` should be reset whenever
``G._pred`` is set to a new value.
Warning: most of the time, when ``G._pred`` is set, ``G._adj`` should also
be set to maintain a valid data structure. They share datadicts.
This object sits on a class and ensures that any instance of that
class clears its cached property "pred" whenever the underlying
instance attribute "_pred" is set to a new object. It only affects
Expand All @@ -63,8 +77,11 @@ class clears its cached property "pred" whenever the underlying
def __set__(self, obj, value):
od = obj.__dict__
od["_pred"] = value
if "pred" in od:
del od["pred"]
# reset cached properties
props = ["pred", "in_edges", "degree", "out_degree", "in_degree"]
for prop in props:
if prop in od:
del od[prop]


class DiGraph(Graph):
Expand Down
8 changes: 6 additions & 2 deletions networkx/classes/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ class clears its cached property "adj" whenever the underlying
def __set__(self, obj, value):
od = obj.__dict__
od["_adj"] = value
if "adj" in od:
del od["adj"]
# reset cached properties
props = ["adj", "edges", "degree"]
for prop in props:
if prop in od:
del od[prop]


class _CachedPropertyResetterNode:
Expand All @@ -59,6 +62,7 @@ class clears its cached property "nodes" whenever the underlying
def __set__(self, obj, value):
od = obj.__dict__
od["_node"] = value
# reset cached properties
if "nodes" in od:
del od["nodes"]

Expand Down
Loading

0 comments on commit 638051a

Please sign in to comment.