Skip to content

Commit

Permalink
COMPAT: h3 v4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis committed Oct 21, 2024
1 parent e23998a commit e8c0da0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions ci/310-oldest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- zstd
- xarray=2022.3
- pandana
- h3-py<4
- pip
- pip:
- pulp
Expand Down
26 changes: 19 additions & 7 deletions libpysal/graph/_indices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from packaging.version import Version


def _build_from_h3(ids, order=1):
"""Generate Graph from H3 hexagons.
Expand Down Expand Up @@ -30,14 +33,23 @@ def _build_from_h3(ids, order=1):

neighbors = {}
weights = {}
for ix in ids:
rings = h3.hex_range_distances(ix, order)
for i, ring in enumerate(rings):
if i == 0:
neighbors[ix] = []
weights[ix] = []
else:
if Version(h3.__version__) > Version("4.0"):
for ix in ids:
neighbors[ix] = []
weights[ix] = []
for i in range(1, order + 1):
ring = h3.grid_ring(ix, i)
neighbors[ix].extend(list(ring))
weights[ix].extend([i] * len(ring))
else:
for ix in ids:
rings = h3.hex_range_distances(ix, order)
for i, ring in enumerate(rings):
if i == 0:
neighbors[ix] = []
weights[ix] = []

Check warning on line 50 in libpysal/graph/_indices.py

View check run for this annotation

Codecov / codecov/patch

libpysal/graph/_indices.py#L45-L50

Added lines #L45 - L50 were not covered by tests
else:
neighbors[ix].extend(list(ring))
weights[ix].extend([i] * len(ring))

Check warning on line 53 in libpysal/graph/_indices.py

View check run for this annotation

Codecov / codecov/patch

libpysal/graph/_indices.py#L52-L53

Added lines #L52 - L53 were not covered by tests

return neighbors, weights

0 comments on commit e8c0da0

Please sign in to comment.