File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -262,13 +262,15 @@ def from_adjlist(
262262 if try_weightcol is None :
263263 adjlist = adjlist .copy (deep = True )
264264 adjlist ["weight" ] = 1
265- all_ids = set (adjlist [focal_col ].tolist ())
266- all_ids |= set (adjlist [neighbor_col ].tolist ())
267265 grouper = adjlist .groupby (focal_col )
268- neighbors = grouper [neighbor_col ].apply (list ).to_dict ()
269- weights = grouper [weight_col ].apply (list ).to_dict ()
270- neighbors .update ({k : [] for k in all_ids .difference (list (neighbors .keys ()))})
271- weights .update ({k : [] for k in all_ids .difference (list (weights .keys ()))})
266+ neighbors = dict ()
267+ weights = dict ()
268+ for ix , chunk in grouper :
269+ neighbors_to_ix = chunk [neighbor_col ].values
270+ weights_to_ix = chunk [weight_col ].values
271+ mask = neighbors_to_ix != ix
272+ neighbors [ix ] = neighbors_to_ix [mask ].tolist ()
273+ weights [ix ] = weights_to_ix [mask ].tolist ()
272274 return cls (neighbors = neighbors , weights = weights )
273275
274276 def to_adjlist (
You can’t perform that action at this time.
0 commit comments