Skip to content

Commit

Permalink
Change default return type `PropertyGraph.extract_subgraph() -> cugra…
Browse files Browse the repository at this point in the history
…ph.Graph(directed=True)` (#2460)

Fixes #2459

The tests already specify the use of directed graphs most places, so this required minimal changes.

Authors:
  - Erik Welch (https://github.com/eriknw)

Approvers:
  - Rick Ratzel (https://github.com/rlratzel)

URL: #2460
  • Loading branch information
eriknw authored Jul 28, 2022
1 parent d925926 commit aca180a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions python/cugraph/cugraph/dask/structure/mg_property_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def select_edges(self, expr):
edge_selection_series=selected_col)

def extract_subgraph(self,
create_using=cugraph.Graph,
create_using=None,
selection=None,
edge_weight_property=None,
default_edge_weight=None,
Expand All @@ -494,12 +494,12 @@ def extract_subgraph(self,
Parameters
----------
create_using : cugraph Graph type or instance
create_using : cugraph Graph type or instance, optional
Creates a Graph to return using the type specified. If an instance
is specified, the type of the instance is used to construct the
return Graph, and all relevant attributes set on the instance are
copied to the return Graph (eg. directed). If not specified the
returned Graph will be a cugraph.Graph instance.
returned Graph will be a directed cugraph.Graph instance.
selection : PropertySelection
A PropertySelection returned from one or more calls to
select_vertices() and/or select_edges(), used for creating a Graph
Expand Down Expand Up @@ -576,6 +576,12 @@ def extract_subgraph(self,
# values. Restore the original dtypes in the resulting edges df prior
# to creating a Graph.
self.__update_dataframe_dtypes(edges, self.__edge_prop_dtypes)

# Default create_using set here instead of function signature to
# prevent cugraph from running on import. This may help diagnose errors
if create_using is None:
create_using = cugraph.Graph(directed=True)

return self.edge_props_to_graph(
edges,
create_using=create_using,
Expand Down
11 changes: 8 additions & 3 deletions python/cugraph/cugraph/structure/property_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def select_edges(self, expr):
edge_selection_series=selected_col)

def extract_subgraph(self,
create_using=cugraph.Graph,
create_using=None,
selection=None,
edge_weight_property=None,
default_edge_weight=None,
Expand All @@ -577,12 +577,12 @@ def extract_subgraph(self,
Parameters
----------
create_using : cugraph Graph type or instance
create_using : cugraph Graph type or instance, optional
Creates a Graph to return using the type specified. If an instance
is specified, the type of the instance is used to construct the
return Graph, and all relevant attributes set on the instance are
copied to the return Graph (eg. directed). If not specified the
returned Graph will be a cugraph.Graph instance.
returned Graph will be a directed cugraph.Graph instance.
selection : PropertySelection
A PropertySelection returned from one or more calls to
select_vertices() and/or select_edges(), used for creating a Graph
Expand Down Expand Up @@ -661,6 +661,11 @@ def extract_subgraph(self,
# to creating a Graph.
edges = self.__update_dataframe_dtypes(edges, self.__edge_prop_dtypes)

# Default create_using set here instead of function signature to
# prevent cugraph from running on import. This may help diagnose errors
if create_using is None:
create_using = cugraph.Graph(directed=True)

return self.edge_props_to_graph(
edges,
create_using=create_using,
Expand Down
1 change: 1 addition & 0 deletions python/cugraph/cugraph/tests/test_property_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ def test_extract_subgraph_no_edges(dataset1_PropertyGraph):

selection = pG.select_vertices("(_TYPE_=='merchants') & (merchant_id==86)")
G = pG.extract_subgraph(selection=selection)
assert G.is_directed()

assert len(G.edgelist.edgelist_df) == 0

Expand Down

0 comments on commit aca180a

Please sign in to comment.