Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
knaaptime committed Nov 2, 2023
1 parent eab274c commit dd4b7d2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libpysal/graph/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def _explore_graph(
focal = [focal]
adj = adj[adj["focal"].isin(focal)].reset_index()

origins = gdf.loc[adj.focal].get_coordinates().values
destinations = gdf.loc[adj.neighbor].get_coordinates().values
origins = gdf.loc[adj.focal].geometry.get_coordinates().values
destinations = gdf.loc[adj.neighbor].geometry.get_coordinates().values
lines = gpd.GeoSeries(
shapely.linestrings(np.hstack([origins, destinations]).reshape(-1, 2, 2)),
crs=gdf.crs,
Expand Down
26 changes: 26 additions & 0 deletions libpysal/graph/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shapely

from libpysal import graph
from libpysal.graph.tests.test_utils import fetch_map_string

matplotlib = pytest.importorskip("matplotlib")

Expand Down Expand Up @@ -253,3 +254,28 @@ def test_focal_kws(self):
np.testing.assert_array_equal(
pathcollection_focal.get_facecolor(), np.array([[0.0, 0.0, 1.0, 1.0]])
)

def test_explore(self):
m = self.G_str.explore(self.nybb_str)
s = fetch_map_string(m)

assert '"focal":"Queens","neighbor":"Bronx","weight":1}' in s
assert s.count("black") ==20
assert s.count("Brooklyn") ==6

def test_explore_options(self):
m = self.nybb.explore(tiles="CartoDB Positron", tooltip=False)
m = self.G_str.explore(self.nybb_str, m=m)
m = self.G_str.explore(
self.nybb_str,
focal="Queens",
m=m,
edge_kws={"color": "red"},
focal_kws={"color": "blue", "marker_kwds": {"radius": 8}},
)
s = fetch_map_string(m)
assert s.count("Manhattan") == 12
assert s.count("Queens") == 14
assert s.count("Brooklyn") == 10
assert s.count("black") == 25
assert '"focal":"Queens","neighbor":"Bronx","weight":1}' in s
5 changes: 5 additions & 0 deletions libpysal/graph/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ def test_validate_raises(
_validate_geometry_input(
numpy.arange(20).reshape(-1, 2), valid_geometry_types=contiguity_types
)

def fetch_map_string(m):
out = m._parent.render()
out_str = "".join(out.split())
return out_str

0 comments on commit dd4b7d2

Please sign in to comment.