Skip to content

Commit c2054e5

Browse files
committed
add test of row_st code to help coverage bot
1 parent fa7d200 commit c2054e5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

libpysal/weights/tests/test_util.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ def test_lat2_w(self):
2525
assert w9[0] == {1: 1.0, 3: 1.0}
2626
assert w9[3] == {0: 1.0, 4: 1.0, 6: 1.0}
2727

28-
def test_lat2_sw(self):
29-
w9 = util.lat2SW(3, 3)
28+
@pytest.mark.parametrize("row_st", [True, False])
29+
def test_lat2_sw(self, row_st):
30+
w9 = util.lat2SW(3, 3, row_st=row_st)
3031
rows, cols = w9.shape
3132
n = rows * cols
3233
assert w9.nnz == 24
3334
pct_nonzero = w9.nnz / float(n)
3435
assert pct_nonzero == 0.29629629629629628
36+
if row_st:
37+
# these 3 lines can be replaced when scipy >=1.15 is assured.
38+
# w9 = (w9.T.multiply(w9.tocsr().count_nonzero(axis=1))).T
39+
w9csr = w9.tocsr()
40+
nnz_by_axis1 = np.diff(w9csr.indptr)
41+
w9 = (w9csr.T.multiply(nnz_by_axis1)).T
3542
data = w9.todense().tolist()
3643
assert data[0] == [0, 1, 0, 1, 0, 0, 0, 0, 0]
3744
assert data[1] == [1, 0, 1, 0, 1, 0, 0, 0, 0]

0 commit comments

Comments
 (0)