Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PropertyGraph.renumber_*_by_type with only default types #3352

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions python/cugraph/cugraph/dask/structure/mg_property_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,10 @@ def renumber_vertices_by_type(self, prev_id_column=None):
# Include self.vertex_col_name when sorting by values to ensure we can
# evenly distribute the data across workers.
df = df.reset_index().persist()
df = df.sort_values(by=[TCN, self.vertex_col_name], ignore_index=True).persist()
if len(self.vertex_types) > 1:
df = df.sort_values(
by=[TCN, self.vertex_col_name], ignore_index=True
).persist()
if self.__edge_prop_dataframe is not None:
new_name = f"new_{self.vertex_col_name}"
df[new_name] = 1
Expand Down Expand Up @@ -1522,9 +1525,10 @@ def renumber_edges_by_type(self, prev_id_column=None):
# Include self.edge_id_col_name when sorting by values to ensure we can
# evenly distribute the data across workers.
df = df.reset_index().persist()
df = df.sort_values(
by=[self.type_col_name, self.edge_id_col_name], ignore_index=True
).persist()
if len(self.edge_types) > 1:
df = df.sort_values(
by=[self.type_col_name, self.edge_id_col_name], ignore_index=True
).persist()
if prev_id_column is not None:
df[prev_id_column] = df[self.edge_id_col_name]

Expand All @@ -1540,8 +1544,8 @@ def renumber_edges_by_type(self, prev_id_column=None):

# FIXME DASK_CUDF: https://github.com/rapidsai/cudf/issues/11795
alexbarghi-nv marked this conversation as resolved.
Show resolved Hide resolved
df = self._edge_type_value_counts
assert df.index.dtype == cat_dtype
df.index = df.index.astype(str)
if df.index.dtype == cat_dtype:
df.index = df.index.astype(str)

# self._edge_type_value_counts
rv = df.sort_index().cumsum().to_frame("stop")
Expand Down
2 changes: 2 additions & 0 deletions python/cugraph/cugraph/structure/property_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,7 @@ def renumber_vertices_by_type(self, prev_id_column=None):
].astype(cat_dtype)

index_dtype = self.__vertex_prop_dataframe.index.dtype
# Should we avoid `sort_values` if we know there is only one type?
alexbarghi-nv marked this conversation as resolved.
Show resolved Hide resolved
df = self.__vertex_prop_dataframe.reset_index().sort_values(by=TCN)
df.index = df.index.astype(index_dtype)
if self.__edge_prop_dataframe is not None:
Expand Down Expand Up @@ -2071,6 +2072,7 @@ def renumber_edges_by_type(self, prev_id_column=None):

df = self.__edge_prop_dataframe
index_dtype = df.index.dtype
# Should we avoid `sort_values` if we know there is only one type?
alexbarghi-nv marked this conversation as resolved.
Show resolved Hide resolved
if prev_id_column is None:
df = df.sort_values(by=TCN, ignore_index=True)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,37 @@ def test_types_from_numerals(dask_client):
]


@pytest.mark.mg
def test_renumber_by_type_only_default_type(dask_client):
from cugraph.experimental import MGPropertyGraph

pG = MGPropertyGraph()
df = cudf.DataFrame(
{
"src": cp.array([0, 0, 1, 2, 2, 3], dtype="int32"),
"dst": cp.array([1, 2, 4, 3, 4, 1], dtype="int32"),
}
)
ddf = dask_cudf.from_cudf(df, npartitions=2)
pG.add_edge_data(ddf, vertex_col_names=["src", "dst"])

df2 = cudf.DataFrame(
{
"prop1": [100, 200, 300, 400, 500],
"prop2": [5, 4, 3, 2, 1],
"id": cp.array([0, 1, 2, 3, 4], dtype="int32"),
}
)
ddf2 = dask_cudf.from_cudf(df2, npartitions=2)
pG.add_vertex_data(ddf2, vertex_col_name="id")
pG.renumber_vertices_by_type()
got = pG.get_vertex_data().compute()
assert got[pG.vertex_col_name].to_arrow().to_pylist() == list(range(len(got)))
pG.renumber_edges_by_type()
got = pG.get_edge_data().compute()
assert got[pG.edge_id_col_name].to_arrow().to_pylist() == list(range(len(got)))


# =============================================================================
# Benchmarks
# =============================================================================
Expand Down