Skip to content

Commit

Permalink
Merge pull request #528 from ljwolf/main
Browse files Browse the repository at this point in the history
fix indexing issue with adjlist construction
  • Loading branch information
ljwolf committed May 24, 2023
2 parents d5ea8f9 + 40e71bf commit 8fa39a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion libpysal/weights/tests/test_adjlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_sort(self):
usv = np.array(["53", "53", "30", "30", "30"])
np.testing.assert_array_equal(unsorted_al.focal.values[:5], usv)
np.testing.assert_array_equal(sorted_al.focal.values[:5], sv)

def test_ids(self):
df = geopandas.read_file(examples.get_path("columbus.dbf")).head()
df["my_id"] = range(3, len(df) + 3)
Expand All @@ -187,3 +187,9 @@ def test_str_ids(self):
assert i in snakes
for i in W_adj.neighbor:
assert i in snakes

def test_lat2w(self):
w = lat2W(5, 5)
manual_neighbors = w.to_adjlist().groupby("focal").neighbor.agg(list).to_dict()
for focal, neighbors in w.neighbors.items():
self.assertEqual(set(manual_neighbors[focal]), set(neighbors))
2 changes: 1 addition & 1 deletion libpysal/weights/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def to_adjlist(

links = []
focal_ix, neighbor_ix = self.sparse.nonzero()
idxs = np.array(list(self.neighbors.keys()))
idxs = np.array(self.id_order)
focal_ix = idxs[focal_ix]
neighbor_ix = idxs[neighbor_ix]
weights = self.sparse.data
Expand Down

0 comments on commit 8fa39a8

Please sign in to comment.