Skip to content

Commit 42f0940

Browse files
authored
Merge pull request #426 from ljwolf/lat2sw_bug
cast sw to csc and eliminate zeros
2 parents 14295a0 + 238e017 commit 42f0940

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

libpysal/weights/tests/test_util.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
except:
1919
HAS_GEOPANDAS = False
2020

21-
SCIPY1_7 = False
22-
if scipy.version.version.startswith("1.7"):
23-
SCIPY1_7 = True
24-
2521

2622
class Testutil(unittest.TestCase):
2723
def setUp(self):
@@ -35,7 +31,6 @@ def test_lat2W(self):
3531
self.assertEqual(w9[0], {1: 1.0, 3: 1.0})
3632
self.assertEqual(w9[3], {0: 1.0, 4: 1.0, 6: 1.0})
3733

38-
@unittest.skipIf(SCIPY1_7, "Known failure due to dia change (TOFIX)")
3934
def test_lat2SW(self):
4035
w9 = util.lat2SW(3, 3)
4136
rows, cols = w9.shape

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)