Skip to content

Commit ee8a3b7

Browse files
committed
cast sw to csc and eliminate zeros
1 parent 14295a0 commit ee8a3b7

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

libpysal/weights/util.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,8 @@ def lat2SW(nrows=3, ncols=5, criterion="rook", row_st=False):
12411241
m = m + m.T
12421242
if row_st:
12431243
m = sparse.spdiags(1.0 / m.sum(1).T, 0, *m.shape) * m
1244+
m = m.tocsc()
1245+
m.eliminate_zeros()
12441246
return m
12451247

12461248

@@ -1510,8 +1512,17 @@ def nonplanar_neighbors(w, geodataframe, tolerance=0.001, **kwargs):
15101512
w.non_planar_joins = fixes
15111513
return w
15121514

1513-
@requires('geopandas')
1514-
def fuzzy_contiguity(gdf, tolerance=0.005, buffering=False, drop=True, buffer=None, predicate='intersects', **kwargs):
1515+
1516+
@requires("geopandas")
1517+
def fuzzy_contiguity(
1518+
gdf,
1519+
tolerance=0.005,
1520+
buffering=False,
1521+
drop=True,
1522+
buffer=None,
1523+
predicate="intersects",
1524+
**kwargs,
1525+
):
15151526
"""
15161527
Fuzzy contiguity spatial weights
15171528
@@ -1625,7 +1636,7 @@ def fuzzy_contiguity(gdf, tolerance=0.005, buffering=False, drop=True, buffer=No
16251636
new_geometry = gdf.geometry.buffer(buffer)
16261637
gdf["_buffer"] = new_geometry
16271638
old_geometry_name = gdf.geometry.name
1628-
gdf.set_geometry('_buffer', inplace=True)
1639+
gdf.set_geometry("_buffer", inplace=True)
16291640

16301641
neighbors = {}
16311642
if GPD_08:
@@ -1641,8 +1652,8 @@ def fuzzy_contiguity(gdf, tolerance=0.005, buffering=False, drop=True, buffer=No
16411652
ids = gdf.index[res[inp == i]].tolist()
16421653
neighbors[ix] = ids
16431654
else:
1644-
if predicate != 'intersects':
1645-
raise ValueError(f'Predicate `{predicate}` requires geopandas >= 0.8.0.')
1655+
if predicate != "intersects":
1656+
raise ValueError(f"Predicate `{predicate}` requires geopandas >= 0.8.0.")
16461657
tree = gdf.sindex
16471658
for i, (ix, geom) in enumerate(gdf.geometry.iteritems()):
16481659
hits = list(tree.intersection(geom.bounds))

0 commit comments

Comments
 (0)