Skip to content

Commit

Permalink
Fix _nxver comparisons for variable length tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Nov 8, 2024
1 parent e42d44d commit ff75d3d
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion nx_cugraph/algorithms/bipartite/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def complete_bipartite_graph(n1, n2, create_using=None):
nodes.extend(range(n2) if nodes2 is None else nodes2)
if len(set(nodes)) != len(nodes):
raise nx.NetworkXError("Inputs n1 and n2 must contain distinct nodes")
if _nxver <= (3, 3):
if _nxver < (3, 4):
name = f"complete_bipartite_graph({orig_n1}, {orig_n2})"
else:
name = f"complete_bipartite_graph({n1}, {n2})"
Expand Down
2 changes: 1 addition & 1 deletion nx_cugraph/algorithms/community/louvain.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
__all__ = ["louvain_communities"]

# max_level argument was added to NetworkX 3.3
if _nxver <= (3, 2):
if _nxver < (3, 3):
_max_level_param = {
"max_level : int, optional": (
"Upper limit of the number of macro-iterations (max: 500)."
Expand Down
2 changes: 1 addition & 1 deletion nx_cugraph/algorithms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def k_truss(G, k):
else:
is_compat_graph = False
if nxcg.number_of_selfloops(G) > 0:
if _nxver <= (3, 2):
if _nxver < (3, 3):
exc_class = nx.NetworkXError
else:
exc_class = nx.NetworkXNotImplemented
Expand Down
2 changes: 1 addition & 1 deletion nx_cugraph/algorithms/link_analysis/hits_alg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def hits(
if nstart is not None:
nstart = G._dict_to_nodearray(nstart, 0, dtype)
if max_iter <= 0:
if _nxver <= (3, 2):
if _nxver < (3, 3):
raise ValueError("`maxiter` must be a positive integer.")
raise nx.PowerIterationFailedConvergence(max_iter)
try:
Expand Down
4 changes: 2 additions & 2 deletions nx_cugraph/algorithms/shortest_paths/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def shortest_path(
paths = nxcg.all_pairs_dijkstra_path(G, weight=weight, dtype=dtype)
else: # method == 'bellman-ford':
paths = nxcg.all_pairs_bellman_ford_path(G, weight=weight, dtype=dtype)
if _nxver <= (3, 4):
if _nxver < (3, 5):
paths = dict(paths)
# To target
elif method == "unweighted":
Expand Down Expand Up @@ -130,7 +130,7 @@ def shortest_path_length(
# To target
elif method == "unweighted":
lengths = nxcg.single_target_shortest_path_length(G, target)
if _nxver <= (3, 4):
if _nxver < (3, 5):
lengths = dict(lengths)
elif method == "dijkstra":
lengths = nxcg.single_source_dijkstra_path_length(
Expand Down
4 changes: 2 additions & 2 deletions nx_cugraph/algorithms/shortest_paths/unweighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def single_source_shortest_path_length(G, source, cutoff=None):
def single_target_shortest_path_length(G, target, cutoff=None):
G = _to_graph(G)
rv = _bfs(G, target, cutoff, "Target", return_type="length")
if _nxver <= (3, 4):
if _nxver < (3, 5):
return iter(rv.items())
return rv

Expand All @@ -62,7 +62,7 @@ def bidirectional_shortest_path(G, source, target):
# TODO PERF: do bidirectional traversal in core
G = _to_graph(G)
if source not in G or target not in G:
if _nxver <= (3, 3):
if _nxver < (3, 4):
raise nx.NodeNotFound(
f"Either source {source} or target {target} is not in G"
)
Expand Down
2 changes: 1 addition & 1 deletion nx_cugraph/algorithms/traversal/breadth_first_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _bfs(G, source, *, depth_limit=None, reverse=False):
return distances[mask], predecessors[mask], node_ids[mask]


if _nxver <= (3, 3):
if _nxver < (3, 4):

@networkx_algorithm(is_incomplete=True, version_added="24.02", _plc="bfs")
def generic_bfs_edges(
Expand Down
2 changes: 1 addition & 1 deletion nx_cugraph/convert_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def from_pandas_edgelist(
and (
# In nx <= 3.3, `edge_key` was ignored if `edge_attr` is None
edge_attr is not None
or _nxver > (3, 3)
or _nxver >= (3, 4)
)
):
try:
Expand Down
4 changes: 2 additions & 2 deletions nx_cugraph/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def key(testpath):
}
)

if _nxver <= (3, 2):
if _nxver < (3, 3):
xfail.update(
{
# NetworkX versions prior to 3.2.1 have tests written to
Expand Down Expand Up @@ -265,7 +265,7 @@ def key(testpath):
}
)

if _nxver <= (3, 1):
if _nxver < (3, 2):
# MAINT: networkx 3.0, 3.1
# NetworkX 3.2 added the ability to "fallback to nx" if backend algorithms
# raise NotImplementedError or `can_run` returns False. The tests below
Expand Down
4 changes: 2 additions & 2 deletions nx_cugraph/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __new__(
_plc=_plc,
)
instance = object.__new__(cls)
if nodes_or_number is not None and _nxver > (3, 2):
if nodes_or_number is not None and _nxver >= (3, 3):
func = nx.utils.decorators.nodes_or_number(nodes_or_number)(func)
# update_wrapper sets __wrapped__, which will be used for the signature
update_wrapper(instance, func)
Expand Down Expand Up @@ -121,7 +121,7 @@ def __new__(
# Set methods so they are in __dict__
instance._can_run = instance._can_run
instance._should_run = instance._should_run
if nodes_or_number is not None and _nxver <= (3, 2):
if nodes_or_number is not None and _nxver < (3, 3):
instance = nx.utils.decorators.nodes_or_number(nodes_or_number)(instance)
return instance

Expand Down

0 comments on commit ff75d3d

Please sign in to comment.