Skip to content

Commit f6da1e5

Browse files
committed
resolve testing to workaround libpysal#322
1 parent e8fd4c0 commit f6da1e5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

libpysal/weights/tests/test_adjlist.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ def test_filter(self):
3131
alist = grid.to_adjlist(remove_symmetric=True)
3232
assert len(alist) == 4
3333
with self.assertRaises(AssertionError):
34-
badgrid = weights.W.from_adjlist(alist)
34+
# build this manually because of bug libpysal#322
35+
alist_neighbors = alist.groupby('focal').neighbor.apply(list).to_dict()
36+
all_ids = set(alist_neighbors.keys()).union(*map(set, alist_neighbors.values()))
37+
for idx in set(all_ids).difference(set(alist_neighbors.keys())):
38+
alist_neighbors[idx] = []
39+
badgrid = weights.W(alist_neighbors)
3540
np.testing.assert_allclose(badgrid.sparse.toarray(),
3641
grid.sparse.toarray())
3742
assert set(alist.focal.unique()) == {0, 1, 2}
@@ -41,10 +46,14 @@ def test_filter(self):
4146
alist = grid.to_adjlist(remove_symmetric=True)
4247
assert len(alist) == 4
4348
with self.assertRaises(AssertionError):
44-
badgrid = weights.W.from_adjlist(alist)
49+
# build this manually because of bug libpysal#322
50+
alist_neighbors = alist.groupby('focal').neighbor.apply(list).to_dict()
51+
all_ids = set(alist_neighbors.keys()).union(*map(set, alist_neighbors.values()))
52+
for idx in set(all_ids).difference(set(alist_neighbors.keys())):
53+
alist_neighbors[idx] = []
54+
badgrid = weights.W(alist_neighbors)
4555
np.testing.assert_allclose(badgrid.sparse.toarray(),
4656
grid.sparse.toarray())
47-
print(alist)
4857
tuples = set([tuple(t) for t in alist[['focal','neighbor']].values])
4958
full_alist = grid.to_adjlist()
5059
all_possible = set([tuple(t) for t in full_alist[['focal','neighbor']].values])

0 commit comments

Comments
 (0)