Skip to content

Commit

Permalink
Merge branch 'rapidsai:branch-24.04' into b2404-cleanup-mg-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nv-rliu authored Feb 27, 2024
2 parents a8eac3f + d1ed728 commit 9f792d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
32 changes: 18 additions & 14 deletions python/nx-cugraph/_nx_cugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
"wheel_graph",
# END: functions
},
"extra_docstrings": {
# BEGIN: extra_docstrings
"additional_docs": {
# BEGIN: additional_docs
"average_clustering": "Directed graphs and `weight` parameter are not yet supported.",
"betweenness_centrality": "`weight` parameter is not yet supported, and RNG with seed may be different.",
"bfs_edges": "`sort_neighbors` parameter is not yet supported.",
Expand All @@ -148,10 +148,10 @@
"louvain_communities": "`seed` parameter is currently ignored, and self-loops are not yet supported.",
"pagerank": "`dangling` parameter is not supported, but it is checked for validity.",
"transitivity": "Directed graphs are not yet supported.",
# END: extra_docstrings
# END: additional_docs
},
"extra_parameters": {
# BEGIN: extra_parameters
"additional_parameters": {
# BEGIN: additional_parameters
"eigenvector_centrality": {
"dtype : dtype or None, optional": "The data type (np.float32, np.float64, or None) to use for the edge weights in the algorithm. If None, then dtype is determined by the edge values.",
},
Expand All @@ -168,7 +168,7 @@
"pagerank": {
"dtype : dtype or None, optional": "The data type (np.float32, np.float64, or None) to use for the edge weights in the algorithm. If None, then dtype is determined by the edge values.",
},
# END: extra_parameters
# END: additional_parameters
},
}

Expand All @@ -178,20 +178,24 @@ def get_info():
This tells NetworkX about the cugraph backend without importing nx_cugraph.
"""
# Convert to e.g. `{"functions": {"myfunc": {"extra_docstring": ...}}}`
# Convert to e.g. `{"functions": {"myfunc": {"additional_docs": ...}}}`
d = _info.copy()
info_keys = {
"extra_docstrings": "extra_docstring",
"extra_parameters": "extra_parameters",
}
info_keys = {"additional_docs", "additional_parameters"}
d["functions"] = {
func: {
new_key: vals[func]
for old_key, new_key in info_keys.items()
if func in (vals := d[old_key])
info_key: vals[func]
for info_key in info_keys
if func in (vals := d[info_key])
}
for func in d["functions"]
}
# Add keys for Networkx <3.3
for func_info in d["functions"].values():
if "additional_docs" in func_info:
func_info["extra_docstring"] = func_info["additional_docs"]
if "additional_parameters" in func_info:
func_info["extra_parameters"] = func_info["additional_parameters"]

for key in info_keys:
del d[key]
return d
Expand Down
24 changes: 12 additions & 12 deletions python/nx-cugraph/_nx_cugraph/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -24,13 +24,13 @@ def get_functions():
}


def get_extra_docstrings(functions=None):
def get_additional_docs(functions=None):
if functions is None:
functions = get_functions()
return {key: val.extra_doc for key, val in functions.items() if val.extra_doc}


def get_extra_parameters(functions=None):
def get_additional_parameters(functions=None):
if functions is None:
functions = get_functions()
return {key: val.extra_params for key, val in functions.items() if val.extra_params}
Expand Down Expand Up @@ -73,18 +73,18 @@ def main(filepath):
to_add = [f'"{name}",' for name in sorted(functions)]
text = update_text(text, to_add, "functions")

# Update extra_docstrings
extra_docstrings = get_extra_docstrings(functions)
to_add = list(dict_to_lines(extra_docstrings))
text = update_text(text, to_add, "extra_docstrings")
# Update additional_docs
additional_docs = get_additional_docs(functions)
to_add = list(dict_to_lines(additional_docs))
text = update_text(text, to_add, "additional_docs")

# Update extra_parameters
extra_parameters = get_extra_parameters(functions)
# Update additional_parameters
additional_parameters = get_additional_parameters(functions)
to_add = []
for name in sorted(extra_parameters):
params = extra_parameters[name]
for name in sorted(additional_parameters):
params = additional_parameters[name]
to_add.append(f"{name!r}: {{")
to_add.extend(dict_to_lines(params, indent=" " * 4))
to_add.append("},")
text = update_text(text, to_add, "extra_parameters")
text = update_text(text, to_add, "additional_parameters")
return text

0 comments on commit 9f792d4

Please sign in to comment.