Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMPAT: h3 v4 compatibility #768

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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
Loading