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

fixes BUG 2275 #2279

Merged
merged 7 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def __from_edgelist(
if self.batch_enabled:
self._replicate_edgelist()

def to_pandas_edgelist(self, source='source', destination='destination'):
def to_pandas_edgelist(self, source='src', destination='dst',
BradReesWork marked this conversation as resolved.
Show resolved Hide resolved
weight='weight'):
"""
Returns the graph edge list as a Pandas DataFrame.

Expand All @@ -192,13 +193,21 @@ def to_pandas_edgelist(self, source='source', destination='destination'):
source column name or array of column names
destination : str or array-like, optional (default='destination')
destination column name or array of column names
weight : str or array-like, optional (default='weight')
weight column name or array of column names

Returns
-------
df : pandas.DataFrame
"""

gdf = self.view_edge_list()
if self.properties.weighted:
gdf.rename(columns={'src': source, 'dst': destination,
'weight': weight}, inplace=True)
else:
gdf.rename(columns={'src': source,
'dst': destination}, inplace=True)
return gdf.to_pandas()

def to_pandas_adjacency(self):
Expand Down
12 changes: 12 additions & 0 deletions python/cugraph/cugraph/tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,18 @@ def test_neighbors(graph_file):
assert cu_neighbors == nx_neighbors


# Test
@pytest.mark.parametrize("graph_file", utils.DATASETS)
def test_to_pandas_edgelist(graph_file):
cu_M = utils.read_csv_file(graph_file)

G = cugraph.Graph()
G.from_cudf_edgelist(cu_M, source="0", destination="1")

assert 's' in G.to_pandas_edgelist('s', 'd').columns
assert 's' in G.to_pandas_edgelist(source='s', destination='d').columns


def test_graph_init_with_multigraph():
"""
Ensures only a valid MultiGraph instance can be used to initialize a Graph
Expand Down