Skip to content
Next Next commit
Update to work with new networkx dispatching
  • Loading branch information
eriknw committed Jun 4, 2023
commit 800b60f66c63197da1fbc67d46ccdc8b015b4965
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:
run: |
conda install -c conda-forge python-graphblas scipy pandas pytest-cov pytest-randomly
# matplotlib lxml pygraphviz pydot sympy # Extra networkx deps we don't need yet
pip install git+https://github.com/networkx/networkx.git@main --no-deps
# pip install git+https://github.com/networkx/networkx.git@main --no-deps
pip install git+https://github.com/eriknw/networkx.git@dispatch_many --no-deps # XXX: temporary
pip install -e . --no-deps
- name: PyTest
run: |
Expand Down
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ repos:
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-ast
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude_types: [svg]
- id: mixed-line-ending
- id: trailing-whitespace
- id: name-tests-test
args: ["--pytest-test-first"]
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.13
hooks:
Expand Down Expand Up @@ -55,7 +61,7 @@ repos:
- id: black
# - id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.269
rev: v0.0.270
hooks:
- id: ruff
args: [--fix-only, --show-fixes]
Expand All @@ -81,7 +87,7 @@ repos:
additional_dependencies: [tomli]
files: ^(graphblas_algorithms|docs)/
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.269
rev: v0.0.270
hooks:
- id: ruff
# `pyroma` may help keep our package standards up to date if best practices change.
Expand Down
28 changes: 27 additions & 1 deletion graphblas_algorithms/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,37 @@ class Dispatcher:
# End auto-generated code: dispatch

@staticmethod
def convert_from_nx(graph, weight=None, *, name=None):
def convert_from_nx(
graph,
edge_attrs=None,
node_attrs=None,
preserve_edge_attrs=None,
preserve_node_attrs=None,
name=None,
*,
weight=None, # For nx.__version__ <= 3.1
):
import networkx as nx

from .classes import DiGraph, Graph, MultiDiGraph, MultiGraph

if preserve_edge_attrs:
raise NotImplementedError("`preserve_edge_attrs=True` is not implemented")
if node_attrs:
raise NotImplementedError("non-None `node_attrs` is not implemented")
if preserve_node_attrs:
raise NotImplementedError("`preserve_node_attrs=True` is not implemented")
if edge_attrs:
if len(edge_attrs) > 1:
raise NotImplementedError(
"Multiple edge attributes is not implemented (bad value for edge_attrs)"
)
if weight is not None:
raise TypeError("edge_attrs and weight both given")
[[weight, default]] = edge_attrs.items()
if default is not None and default != 1:
raise NotImplementedError(f"edge default != 1 is not implemented; got {default}")

if isinstance(graph, nx.MultiDiGraph):
return MultiDiGraph.from_networkx(graph, weight=weight)
if isinstance(graph, nx.MultiGraph):
Expand Down
6 changes: 5 additions & 1 deletion graphblas_algorithms/tests/test_match_nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
"Matching networkx namespace requires networkx to be installed", allow_module_level=True
)
else:
from networkx.classes import backends # noqa: F401
try:
from networkx.utils import backends
except ImportError: # pragma: no cover (import)
# This is the location in nx 3.1
from networkx.classes import backends # noqa: F401


def isdispatched(func):
Expand Down