|
126 | 126 | "source": [ |
127 | 127 | "# Run renumbering\n", |
128 | 128 | "\n", |
129 | | - "Output from renumbering is a data frame and a NumberMap object. The data frame contains the renumbered sources and destinations. The NumberMap will allow you to translate from external to internal vertex identifiers.\n", |
| 129 | + "Output from renumbering is a data frame and a NumberMap object. The data frame contains the renumbered sources and destinations. The NumberMap will allow you to translate from external to internal vertex identifiers. The renumbering call will rename the specified source and destination columns to indicate they were renumbered and no longer contain the original data, and the new names are guaranteed to be unique and not collide with other column names.\n", |
130 | 130 | "\n", |
131 | 131 | "Note that renumbering does not guarantee that the output data frame is in the same order as the input data frame (although in our simple example it will match). To address this we will add the index as a column of gdf before renumbering.\n" |
132 | 132 | ] |
|
140 | 140 | "gdf['order'] = gdf.index\n", |
141 | 141 | "\n", |
142 | 142 | "renumbered_df, numbering = NumberMap.renumber(gdf, ['source_as_int'], ['dest_as_int'])\n", |
| 143 | + "new_src_col_name = numbering.renumbered_src_col_name\n", |
| 144 | + "new_dst_col_name = numbering.renumbered_dst_col_name\n", |
143 | 145 | "\n", |
144 | 146 | "renumbered_df" |
145 | 147 | ] |
|
204 | 206 | "for i in range(len(renumbered_df)):\n", |
205 | 207 | " print(\" \", i,\n", |
206 | 208 | " \": (\", source_as_int[i], \",\", dest_as_int[i],\n", |
207 | | - " \"), renumbered: (\", renumbered_df['src'][i], \",\", renumbered_df['dst'][i], \n", |
| 209 | + " \"), renumbered: (\", renumbered_df[new_src_col_name][i], \",\", renumbered_df[new_dst_col_name][i], \n", |
208 | 210 | " \"), translate back: (\",\n", |
209 | | - " numbering.from_internal_vertex_id(cudf.Series([renumbered_df['src'][i]]))['0'][0], \",\",\n", |
210 | | - " numbering.from_internal_vertex_id(cudf.Series([renumbered_df['dst'][i]]))['0'][0], \")\"\n", |
| 211 | + " numbering.from_internal_vertex_id(cudf.Series([renumbered_df[new_src_col_name][i]]))['0'][0], \",\",\n", |
| 212 | + " numbering.from_internal_vertex_id(cudf.Series([renumbered_df[new_dst_col_name][i]]))['0'][0], \")\"\n", |
211 | 213 | " )\n" |
212 | 214 | ] |
213 | 215 | }, |
|
230 | 232 | "source": [ |
231 | 233 | "G = cugraph.Graph()\n", |
232 | 234 | "gdf_r = cudf.DataFrame()\n", |
233 | | - "gdf_r[\"src\"] = renumbered_df[\"src\"]\n", |
234 | | - "gdf_r[\"dst\"] = renumbered_df[\"dst\"]\n", |
| 235 | + "gdf_r[\"src\"] = renumbered_df[new_src_col_name]\n", |
| 236 | + "gdf_r[\"dst\"] = renumbered_df[new_dst_col_name]\n", |
235 | 237 | "\n", |
236 | 238 | "G.from_cudf_edgelist(gdf_r, source='src', destination='dst', renumber=False)\n", |
237 | 239 | "\n", |
|
0 commit comments