From 7d1df6e070a9c4794d31199ef945322554aca2ad Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Fri, 15 May 2026 00:51:22 +0900 Subject: [PATCH 01/29] ci: declare contents:read on lint_and_coverage workflow Signed-off-by: Arpit Jain --- .github/workflows/lint_and_coverage.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint_and_coverage.yml b/.github/workflows/lint_and_coverage.yml index c0eb154..8ec1ef1 100644 --- a/.github/workflows/lint_and_coverage.yml +++ b/.github/workflows/lint_and_coverage.yml @@ -6,6 +6,9 @@ on: pull_request: branches: ['*'] +permissions: + contents: read + jobs: linting: name: Lint and Coverage From 33badf14f235ec832865949dc8dabba60d56939f Mon Sep 17 00:00:00 2001 From: Marco Barbosa Date: Wed, 17 Jun 2026 23:44:05 +0000 Subject: [PATCH 02/29] annotates .pyx cython files as compatible with freethreading python --- src/h3/_cy/cells.pyx | 1 + src/h3/_cy/edges.pyx | 1 + src/h3/_cy/error_system.pyx | 1 + src/h3/_cy/latlng.pyx | 1 + src/h3/_cy/memory.pyx | 1 + src/h3/_cy/to_multipoly.pyx | 1 + src/h3/_cy/util.pyx | 1 + src/h3/_cy/vertex.pyx | 1 + 8 files changed, 8 insertions(+) diff --git a/src/h3/_cy/cells.pyx b/src/h3/_cy/cells.pyx index 78d2561..8b84f9d 100644 --- a/src/h3/_cy/cells.pyx +++ b/src/h3/_cy/cells.pyx @@ -1,3 +1,4 @@ +# cython: freethreading_compatible=True cimport h3lib from .h3lib cimport bool, int64_t, H3int, H3ErrorCodes diff --git a/src/h3/_cy/edges.pyx b/src/h3/_cy/edges.pyx index bd0aa7c..1d2ef74 100644 --- a/src/h3/_cy/edges.pyx +++ b/src/h3/_cy/edges.pyx @@ -1,3 +1,4 @@ +# cython: freethreading_compatible=True cimport h3lib from .h3lib cimport bool, H3int diff --git a/src/h3/_cy/error_system.pyx b/src/h3/_cy/error_system.pyx index fc18f46..5fe5cd9 100644 --- a/src/h3/_cy/error_system.pyx +++ b/src/h3/_cy/error_system.pyx @@ -1,3 +1,4 @@ +# cython: freethreading_compatible=True """ Exceptions from the h3-py library have three possible sources: diff --git a/src/h3/_cy/latlng.pyx b/src/h3/_cy/latlng.pyx index d83a9d3..1593d43 100644 --- a/src/h3/_cy/latlng.pyx +++ b/src/h3/_cy/latlng.pyx @@ -1,3 +1,4 @@ +# cython: freethreading_compatible=True from libc.stdint cimport uint64_t cimport h3lib diff --git a/src/h3/_cy/memory.pyx b/src/h3/_cy/memory.pyx index 0852105..963b00d 100644 --- a/src/h3/_cy/memory.pyx +++ b/src/h3/_cy/memory.pyx @@ -1,3 +1,4 @@ +# cython: freethreading_compatible=True from cython.view cimport array from .h3lib cimport H3int diff --git a/src/h3/_cy/to_multipoly.pyx b/src/h3/_cy/to_multipoly.pyx index ed3e763..cb5e5e2 100644 --- a/src/h3/_cy/to_multipoly.pyx +++ b/src/h3/_cy/to_multipoly.pyx @@ -1,3 +1,4 @@ +# cython: freethreading_compatible=True cimport h3lib from h3lib cimport H3int from .util cimport check_cell, coord2deg diff --git a/src/h3/_cy/util.pyx b/src/h3/_cy/util.pyx index 9b070f9..06823d0 100644 --- a/src/h3/_cy/util.pyx +++ b/src/h3/_cy/util.pyx @@ -1,3 +1,4 @@ +# cython: freethreading_compatible=True from .h3lib cimport ( H3int, H3str, diff --git a/src/h3/_cy/vertex.pyx b/src/h3/_cy/vertex.pyx index 26a674a..99cc5ef 100644 --- a/src/h3/_cy/vertex.pyx +++ b/src/h3/_cy/vertex.pyx @@ -1,3 +1,4 @@ +# cython: freethreading_compatible=True cimport h3lib from h3lib cimport bool, H3int From 1ed3273533d62a7fe61dbf4fbb35c08e4f3b0599 Mon Sep 17 00:00:00 2001 From: Marco Barbosa Date: Thu, 18 Jun 2026 00:04:12 +0000 Subject: [PATCH 03/29] adds trove for python free threading and changelog --- CHANGELOG.md | 1 + pyproject.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 651c76c..7ad11bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ avoid adding features or APIs which do not map onto the [H3 core API](https://uber.github.io/h3/#/documentation/api-reference/). ## Unreleased +- Fix wheels for Python 3.14.6 free-threading ## [4.5.0] - 2026-05-29 diff --git a/pyproject.toml b/pyproject.toml index f3304b9..2474f88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ classifiers = [ 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: 3.13', 'Programming Language :: Python :: 3.14', + 'Programming Language :: Python :: Free Threading', 'Operating System :: MacOS :: MacOS X', 'Operating System :: POSIX :: Linux', 'Operating System :: Microsoft :: Windows', From 4e9d379a2005866fc1a391b88754ee73381176c8 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Tue, 7 Jul 2026 15:23:28 +0530 Subject: [PATCH 04/29] build: detect Buildozer environment to fix Android cross-compilation --- CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40ce38e..52a76f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,16 @@ cmake_minimum_required(VERSION 3.15...3.26) +# --- BEGIN ANDROID CROSS-COMPILATION FIX --- +# Buildozer/python-for-android uses standard pip install which doesn't natively +# pass a CMake toolchain file to scikit-build-core. This detects the Android compiler +# from the environment and forces CMake into cross-compilation mode to prevent +# it from building host (x86_64) binaries. +if("$ENV{CC}" MATCHES "android" AND NOT DEFINED CMAKE_SYSTEM_NAME) + message(STATUS "Detected Android cross-compilation via environment variables. Setting CMAKE_SYSTEM_NAME=Android") + set(CMAKE_SYSTEM_NAME Android) +endif() +# --- END ANDROID CROSS-COMPILATION FIX --- + project(${SKBUILD_PROJECT_NAME} LANGUAGES C) set(CMAKE_POSITION_INDEPENDENT_CODE ON) From 1d358b275ecdd7164b958982b07b8b6e40afcf5b Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Wed, 22 Jul 2026 09:02:39 +0530 Subject: [PATCH 05/29] feat: add container formatting options to GeoJSON outputs --- src/h3/_h3shape.py | 56 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 5c36295..3586d29 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -184,13 +184,6 @@ LL0: lat/lng or lng/lat pair LL1: list of LL0s LL2: list of LL1s (i.e., a polygon with holes) LL3: list of LL2s (i.e., several polygons with holes) - - -## TODO - -- Allow user to specify "container" in `cells_to_geojson`. - - That is, they may want a MultiPolygon even if the output fits in a Polygon - - 'auto', Polygon, MultiPolygon, FeatureCollection, GeometryCollection, ... """ @@ -325,14 +318,59 @@ def geo_to_h3shape(geo): return shape -def h3shape_to_geo(h3shape): +def h3shape_to_geo(h3shape, container='auto'): """ Translate from an ``H3Shape`` to a ``__geo_interface__`` dict. ``h3shape`` should be either ``LatLngPoly`` or ``LatLngMultiPoly`` + + Parameters + ---------- + container : str, optional + Specify the desired GeoJSON output container. + Options: 'auto', 'Polygon', 'MultiPolygon', 'Feature', + 'FeatureCollection', or 'GeometryCollection'. + Default is 'auto' (returns the simplest valid geometry). Returns ------- dict """ - return h3shape.__geo_interface__ + base_geo = h3shape.__geo_interface__ + + if container == 'auto' or container == base_geo['type']: + return base_geo + + # Upgrade a Polygon to a MultiPolygon if explicitly requested + if container == 'MultiPolygon' and base_geo['type'] == 'Polygon': + return { + 'type': 'MultiPolygon', + 'coordinates': (base_geo['coordinates'],) + } + + if container == 'Feature': + return { + 'type': 'Feature', + 'geometry': base_geo, + 'properties': {} + } + + if container == 'FeatureCollection': + return { + 'type': 'FeatureCollection', + 'features': [{ + 'type': 'Feature', + 'geometry': base_geo, + 'properties': {} + }] + } + + if container == 'GeometryCollection': + return { + 'type': 'GeometryCollection', + 'geometries': [base_geo] + } + + # If a downgrade is requested (e.g., MultiPolygon to Polygon) which + # risks data loss, or an unknown container is passed, return safely. + return base_geo From b1f5f9abc8dc942c49cf4db501e4adbdde52ed38 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Wed, 22 Jul 2026 16:02:28 +0530 Subject: [PATCH 06/29] test: add unit tests for GeoJSON container options; fix linting --- src/h3/_h3shape.py | 14 ++++++------- tests/test_geojson_containers.py | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 tests/test_geojson_containers.py diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 3586d29..93059e7 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -337,24 +337,24 @@ def h3shape_to_geo(h3shape, container='auto'): dict """ base_geo = h3shape.__geo_interface__ - + if container == 'auto' or container == base_geo['type']: return base_geo - + # Upgrade a Polygon to a MultiPolygon if explicitly requested if container == 'MultiPolygon' and base_geo['type'] == 'Polygon': return { 'type': 'MultiPolygon', 'coordinates': (base_geo['coordinates'],) } - + if container == 'Feature': return { 'type': 'Feature', 'geometry': base_geo, 'properties': {} } - + if container == 'FeatureCollection': return { 'type': 'FeatureCollection', @@ -364,13 +364,13 @@ def h3shape_to_geo(h3shape, container='auto'): 'properties': {} }] } - + if container == 'GeometryCollection': return { 'type': 'GeometryCollection', 'geometries': [base_geo] } - - # If a downgrade is requested (e.g., MultiPolygon to Polygon) which + + # If a downgrade is requested (e.g., MultiPolygon to Polygon) which # risks data loss, or an unknown container is passed, return safely. return base_geo diff --git a/tests/test_geojson_containers.py b/tests/test_geojson_containers.py new file mode 100644 index 0000000..2ecf952 --- /dev/null +++ b/tests/test_geojson_containers.py @@ -0,0 +1,35 @@ +import pytest +from h3._h3shape import LatLngPoly, h3shape_to_geo + +def test_h3shape_to_geo_containers(): + # Create a basic dummy polygon for testing + poly = LatLngPoly( + [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34), (37.82, -122.54)] + ) + + # Test 'auto' (Default behavior should return a Polygon) + auto_geo = h3shape_to_geo(poly, container='auto') + assert auto_geo['type'] == 'Polygon' + + # Test MultiPolygon wrapper + mp_geo = h3shape_to_geo(poly, container='MultiPolygon') + assert mp_geo['type'] == 'MultiPolygon' + assert len(mp_geo['coordinates']) == 1 + + # Test Feature wrapper + feat_geo = h3shape_to_geo(poly, container='Feature') + assert feat_geo['type'] == 'Feature' + assert feat_geo['geometry']['type'] == 'Polygon' + + # Test FeatureCollection wrapper + fc_geo = h3shape_to_geo(poly, container='FeatureCollection') + assert fc_geo['type'] == 'FeatureCollection' + assert len(fc_geo['features']) == 1 + assert fc_geo['features'][0]['type'] == 'Feature' + assert fc_geo['features'][0]['geometry']['type'] == 'Polygon' + + # Test GeometryCollection wrapper + gc_geo = h3shape_to_geo(poly, container='GeometryCollection') + assert gc_geo['type'] == 'GeometryCollection' + assert len(gc_geo['geometries']) == 1 + assert gc_geo['geometries'][0]['type'] == 'Polygon' \ No newline at end of file From e02b8a6e95ab66ee31d8a6d77a79e1924d8ed938 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Wed, 22 Jul 2026 20:40:46 +0530 Subject: [PATCH 07/29] fix: raise ValueError for invalid or insufficient GeoJSON containers --- src/h3/_h3shape.py | 8 +++++--- tests/test_geojson_containers.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 93059e7..477a5ec 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -371,6 +371,8 @@ def h3shape_to_geo(h3shape, container='auto'): 'geometries': [base_geo] } - # If a downgrade is requested (e.g., MultiPolygon to Polygon) which - # risks data loss, or an unknown container is passed, return safely. - return base_geo + # If we reach here, the requested container is either unknown or + # insufficient for the data (e.g., requesting a Polygon for MultiPolygon data). + raise ValueError( + f"Requested container '{container}' is invalid or insufficient for data of type '{base_geo['type']}'." + ) diff --git a/tests/test_geojson_containers.py b/tests/test_geojson_containers.py index 2ecf952..bfc3a41 100644 --- a/tests/test_geojson_containers.py +++ b/tests/test_geojson_containers.py @@ -1,5 +1,5 @@ import pytest -from h3._h3shape import LatLngPoly, h3shape_to_geo +from h3._h3shape import LatLngPoly, h3shape_to_geo, LatLngMultiPoly def test_h3shape_to_geo_containers(): # Create a basic dummy polygon for testing @@ -32,4 +32,17 @@ def test_h3shape_to_geo_containers(): gc_geo = h3shape_to_geo(poly, container='GeometryCollection') assert gc_geo['type'] == 'GeometryCollection' assert len(gc_geo['geometries']) == 1 - assert gc_geo['geometries'][0]['type'] == 'Polygon' \ No newline at end of file + assert gc_geo['geometries'][0]['type'] == 'Polygon' + +def test_h3shape_to_geo_invalid_containers(): + # 1. Test an unknown container string + poly = LatLngPoly([(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)]) + with pytest.raises(ValueError, match="invalid or insufficient"): + h3shape_to_geo(poly, container='InvalidString') + + # 2. Test an insufficient container (MultiPolygon data into a Polygon container) + mpoly = LatLngMultiPoly([ + [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)] + ]) + with pytest.raises(ValueError, match="invalid or insufficient"): + h3shape_to_geo(mpoly, container='Polygon') \ No newline at end of file From a2add15580cebc424d66df6081324b103401dc90 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Wed, 22 Jul 2026 22:37:23 +0530 Subject: [PATCH 08/29] test: verify MultiPolygon to MultiPolygon matching; fix line length --- src/h3/_h3shape.py | 12 +++++++----- tests/test_geojson_containers.py | 28 +++++++++++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 477a5ec..7aa7f62 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -323,12 +323,12 @@ def h3shape_to_geo(h3shape, container='auto'): Translate from an ``H3Shape`` to a ``__geo_interface__`` dict. ``h3shape`` should be either ``LatLngPoly`` or ``LatLngMultiPoly`` - + Parameters ---------- container : str, optional - Specify the desired GeoJSON output container. - Options: 'auto', 'Polygon', 'MultiPolygon', 'Feature', + Specify the desired GeoJSON output container. + Options: 'auto', 'Polygon', 'MultiPolygon', 'Feature', 'FeatureCollection', or 'GeometryCollection'. Default is 'auto' (returns the simplest valid geometry). @@ -338,6 +338,7 @@ def h3shape_to_geo(h3shape, container='auto'): """ base_geo = h3shape.__geo_interface__ + # Return immediately if no wrapping is needed if container == 'auto' or container == base_geo['type']: return base_geo @@ -371,8 +372,9 @@ def h3shape_to_geo(h3shape, container='auto'): 'geometries': [base_geo] } - # If we reach here, the requested container is either unknown or + # If we reach here, the requested container is either unknown or # insufficient for the data (e.g., requesting a Polygon for MultiPolygon data). raise ValueError( - f"Requested container '{container}' is invalid or insufficient for data of type '{base_geo['type']}'." + f"Requested container '{container}' is invalid or insufficient " + f"for data of type '{base_geo['type']}'." ) diff --git a/tests/test_geojson_containers.py b/tests/test_geojson_containers.py index bfc3a41..35629d5 100644 --- a/tests/test_geojson_containers.py +++ b/tests/test_geojson_containers.py @@ -1,26 +1,27 @@ import pytest from h3._h3shape import LatLngPoly, h3shape_to_geo, LatLngMultiPoly + def test_h3shape_to_geo_containers(): # Create a basic dummy polygon for testing poly = LatLngPoly( [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34), (37.82, -122.54)] ) - + # Test 'auto' (Default behavior should return a Polygon) auto_geo = h3shape_to_geo(poly, container='auto') assert auto_geo['type'] == 'Polygon' - + # Test MultiPolygon wrapper mp_geo = h3shape_to_geo(poly, container='MultiPolygon') assert mp_geo['type'] == 'MultiPolygon' assert len(mp_geo['coordinates']) == 1 - + # Test Feature wrapper feat_geo = h3shape_to_geo(poly, container='Feature') assert feat_geo['type'] == 'Feature' assert feat_geo['geometry']['type'] == 'Polygon' - + # Test FeatureCollection wrapper fc_geo = h3shape_to_geo(poly, container='FeatureCollection') assert fc_geo['type'] == 'FeatureCollection' @@ -34,15 +35,28 @@ def test_h3shape_to_geo_containers(): assert len(gc_geo['geometries']) == 1 assert gc_geo['geometries'][0]['type'] == 'Polygon' + def test_h3shape_to_geo_invalid_containers(): # 1. Test an unknown container string poly = LatLngPoly([(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)]) - with pytest.raises(ValueError, match="invalid or insufficient"): + with pytest.raises(ValueError, match='invalid or insufficient'): h3shape_to_geo(poly, container='InvalidString') # 2. Test an insufficient container (MultiPolygon data into a Polygon container) mpoly = LatLngMultiPoly([ [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)] ]) - with pytest.raises(ValueError, match="invalid or insufficient"): - h3shape_to_geo(mpoly, container='Polygon') \ No newline at end of file + with pytest.raises(ValueError, match='invalid or insufficient'): + h3shape_to_geo(mpoly, container='Polygon') + + +def test_h3shape_to_geo_exact_match(): + # Test that requesting a MultiPolygon for MultiPolygon data succeeds + mpoly = LatLngMultiPoly([ + [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)] + ]) + + mp_geo = h3shape_to_geo(mpoly, container='MultiPolygon') + + assert mp_geo['type'] == 'MultiPolygon' + assert len(mp_geo['coordinates']) == 1 From 03678bb3ed49ef93a7e84cec1f5cb7d61443fed6 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Sat, 25 Jul 2026 23:16:31 +0530 Subject: [PATCH 09/29] test: fix LatLngMultiPoly initialization to resolve CI crash and restore coverage --- tests/test_geojson_containers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_geojson_containers.py b/tests/test_geojson_containers.py index 35629d5..5421353 100644 --- a/tests/test_geojson_containers.py +++ b/tests/test_geojson_containers.py @@ -43,20 +43,20 @@ def test_h3shape_to_geo_invalid_containers(): h3shape_to_geo(poly, container='InvalidString') # 2. Test an insufficient container (MultiPolygon data into a Polygon container) - mpoly = LatLngMultiPoly([ - [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)] - ]) + mpoly = LatLngMultiPoly( + LatLngPoly([(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)]) + ) with pytest.raises(ValueError, match='invalid or insufficient'): h3shape_to_geo(mpoly, container='Polygon') def test_h3shape_to_geo_exact_match(): # Test that requesting a MultiPolygon for MultiPolygon data succeeds - mpoly = LatLngMultiPoly([ - [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)] - ]) + mpoly = LatLngMultiPoly( + LatLngPoly([(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)]) + ) mp_geo = h3shape_to_geo(mpoly, container='MultiPolygon') assert mp_geo['type'] == 'MultiPolygon' - assert len(mp_geo['coordinates']) == 1 + assert len(mp_geo['coordinates']) == 1 \ No newline at end of file From 55530fa42b34dd7aacc913a65d5ada6d54895fea Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Sun, 26 Jul 2026 00:43:15 +0530 Subject: [PATCH 10/29] test: move tests to test_lib for coverage; fix EOF newline --- tests/{ => test_lib}/test_geojson_containers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{ => test_lib}/test_geojson_containers.py (98%) diff --git a/tests/test_geojson_containers.py b/tests/test_lib/test_geojson_containers.py similarity index 98% rename from tests/test_geojson_containers.py rename to tests/test_lib/test_geojson_containers.py index 5421353..a890c27 100644 --- a/tests/test_geojson_containers.py +++ b/tests/test_lib/test_geojson_containers.py @@ -59,4 +59,4 @@ def test_h3shape_to_geo_exact_match(): mp_geo = h3shape_to_geo(mpoly, container='MultiPolygon') assert mp_geo['type'] == 'MultiPolygon' - assert len(mp_geo['coordinates']) == 1 \ No newline at end of file + assert len(mp_geo['coordinates']) == 1 From 497aa4df24668650e1d3e599511547d6be6b1caa Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Sun, 26 Jul 2026 22:13:45 +0530 Subject: [PATCH 11/29] test: clean up string formatting in test_parent_err --- tests/test_lib/test_cells_and_edges.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index 4b8e107..bae5d69 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -131,9 +131,7 @@ def test_parent_err(): except Exception as e: msg = str(e) - # todo: revist this weird formatting stuff - expected = 'Invalid parent resolution -1 for cell {}.' - expected = expected.format(hex(h3.str_to_int(h))) + expected = f'Invalid parent resolution -1 for cell 0x{h}.' assert msg == expected From 2f62194f0f29c8a8b05439c489604ef2d7a391be Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Tue, 28 Jul 2026 08:34:00 +0530 Subject: [PATCH 12/29] test: add test for uncompacting cells to a coarser resolution --- src/h3/api/basic_int/__init__.py | 2 -- tests/test_lib/test_cells_and_edges.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/h3/api/basic_int/__init__.py b/src/h3/api/basic_int/__init__.py index 1086a63..ef82792 100644 --- a/src/h3/api/basic_int/__init__.py +++ b/src/h3/api/basic_int/__init__.py @@ -474,8 +474,6 @@ def uncompact_cells(cells, res): ----- There is currently no guaranteed order of the output cells. """ - # TODO: add test to make sure an error is returned when input contains cell - # smaller than output res. hc = _in_collection(cells) hu = _cy.uncompact_cells(hc, res) diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index 4b8e107..240a638 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -755,3 +755,13 @@ def test_construct_cell_inverses_int_api(): def test_center_child_with_deconstruct(): for h in h3.get_res0_cells(): h3.construct_cell(*h3.deconstruct_cell(h), 0) == h3.cell_to_center_child(h) + + +def test_uncompact_cells_invalid_resolution(): + # Create a valid cell at resolution 5 + h_res5 = h3.latlng_to_cell(0, 0, 5) + + # Attempting to uncompact to a coarser resolution (4) + # should raise an H3ResDomainError + with pytest.raises(H3ResDomainError): + h3.uncompact_cells({h_res5}, 4) From 8cd64decd00f66379946b35e37adb76531a45786 Mon Sep 17 00:00:00 2001 From: Deepak Yadav Date: Sat, 1 Aug 2026 21:07:42 +0530 Subject: [PATCH 13/29] Update tests/test_lib/test_cells_and_edges.py Co-authored-by: Isaac Brodsky --- tests/test_lib/test_cells_and_edges.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index bae5d69..46e7df2 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -131,7 +131,7 @@ def test_parent_err(): except Exception as e: msg = str(e) - expected = f'Invalid parent resolution -1 for cell 0x{h}.' + expected = f'Invalid parent resolution -1 for cell {h}.' assert msg == expected From 58be699d132f952e186757a5eeaf2bd455857e8d Mon Sep 17 00:00:00 2001 From: Deepak Yadav Date: Sat, 1 Aug 2026 21:11:58 +0530 Subject: [PATCH 14/29] Update tests/test_lib/test_cells_and_edges.py Co-authored-by: Isaac Brodsky --- tests/test_lib/test_cells_and_edges.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index 240a638..2b106e6 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -763,5 +763,5 @@ def test_uncompact_cells_invalid_resolution(): # Attempting to uncompact to a coarser resolution (4) # should raise an H3ResDomainError - with pytest.raises(H3ResDomainError): + with pytest.raises(H3ResMismatchError): h3.uncompact_cells({h_res5}, 4) From 822320f30bf7f9381b5c00c4f7800b7a7b6581bb Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Sun, 2 Aug 2026 10:05:10 +0530 Subject: [PATCH 15/29] test: restore 0x prefix to match actual exception message --- tests/test_lib/test_cells_and_edges.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index 46e7df2..bae5d69 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -131,7 +131,7 @@ def test_parent_err(): except Exception as e: msg = str(e) - expected = f'Invalid parent resolution -1 for cell {h}.' + expected = f'Invalid parent resolution -1 for cell 0x{h}.' assert msg == expected From 5dc46e4f287772f6bef6090ec96b3d2219428485 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Mon, 3 Aug 2026 21:43:59 +0530 Subject: [PATCH 16/29] test: update comment to match H3ResMismatchError --- tests/test_lib/test_cells_and_edges.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index 2b106e6..77e8f5e 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -762,6 +762,6 @@ def test_uncompact_cells_invalid_resolution(): h_res5 = h3.latlng_to_cell(0, 0, 5) # Attempting to uncompact to a coarser resolution (4) - # should raise an H3ResDomainError + # should raise an H3ResMismatchError with pytest.raises(H3ResMismatchError): h3.uncompact_cells({h_res5}, 4) From e3b0a6d96d7ef8e7f68cbcb45b800b37bf383fe8 Mon Sep 17 00:00:00 2001 From: Jongbin Jung Date: Wed, 12 Aug 2026 12:52:02 -0700 Subject: [PATCH 17/29] Add CI test and build for python3.14t --- .github/workflows/tests.yml | 2 +- .github/workflows/wheels.yml | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7920a84..f3dcc3c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-22.04] - python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.14t'] steps: - uses: actions/checkout@v6.0.2 diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index dbc8d6d..b9bc985 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -80,6 +80,9 @@ jobs: - os: windows-11-arm build: 'cp314-win_arm64' name: Windows ARM64 3.14 + - os: windows-11-arm + build: 'cp314t-win_arm64' + name: Windows ARM64 3.14t - os: ubuntu-22.04 build: 'cp*-manylinux_x86_64' @@ -100,6 +103,9 @@ jobs: - os: ubuntu-22.04 build: 'cp314-musllinux_x86_64' name: Linux Intel musl 64-bit 3.14 + - os: ubuntu-22.04 + build: 'cp314t-musllinux_x86_64' + name: Linux Intel musl 64-bit 3.14t - os: ubuntu-22.04 build: 'cp310-manylinux_aarch64' @@ -116,6 +122,9 @@ jobs: - os: ubuntu-22.04 build: 'cp314-manylinux_aarch64' name: Linux Aarch64 3.14 + - os: ubuntu-22.04 + build: 'cp314t-manylinux_aarch64' + name: Linux Aarch64 3.14t steps: - uses: actions/checkout@v6.0.2 From a4bc7398f42bf9cfc1983f09ffa857f58c04c0e9 Mon Sep 17 00:00:00 2001 From: Hashim1999164 <64767361+Hashim1999164@users.noreply.github.com> Date: Sun, 23 Aug 2026 01:32:12 +0500 Subject: [PATCH 18/29] Raise ValueError instead of assert in geo_to_h3shape The leftover assert isinstance check tripped Bandit and was marked for removal. Invalid inputs now get an explicit ValueError. --- src/h3/_h3shape.py | 6 +++++- tests/test_lib/polyfill/test_h3.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 7aa7f62..a8146df 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -301,7 +301,11 @@ def geo_to_h3shape(geo): # get dict geo = geo.__geo_interface__ - assert isinstance(geo, dict) # todo: remove + if not isinstance(geo, dict): + raise ValueError( + 'geo must be a dict or implement __geo_interface__, got: ' + + str(type(geo)) + ) t = geo['type'] coord = geo['coordinates'] diff --git a/tests/test_lib/polyfill/test_h3.py b/tests/test_lib/polyfill/test_h3.py index 72ddd58..fed297f 100644 --- a/tests/test_lib/polyfill/test_h3.py +++ b/tests/test_lib/polyfill/test_h3.py @@ -302,6 +302,11 @@ def test_geo_to_h3shape_passthrough(): assert h3.geo_to_h3shape(shape) is shape +def test_geo_to_h3shape_rejects_non_dict(): + with pytest.raises(ValueError, match='dict or implement __geo_interface__'): + h3.geo_to_h3shape('not a geo object') + + def test_polyfill_down_under(): sydney = [ (-33.8556, 151.1979), From c7b48389da04dffba5b6c0529c60653845bba4e8 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Wed, 26 Aug 2026 22:04:52 +0530 Subject: [PATCH 19/29] fix: replace geo input assert with ValueError and add test --- src/h3/_h3shape.py | 3 ++- tests/test_lib/polyfill/test_polyfill.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 7aa7f62..eadc2e5 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -301,7 +301,8 @@ def geo_to_h3shape(geo): # get dict geo = geo.__geo_interface__ - assert isinstance(geo, dict) # todo: remove + if not isinstance(geo, dict): + raise ValueError(f"Expected a dict or an object with __geo_interface__, but got: {type(geo).__name__}") t = geo['type'] coord = geo['coordinates'] diff --git a/tests/test_lib/polyfill/test_polyfill.py b/tests/test_lib/polyfill/test_polyfill.py index 9bdd9af..5f83be0 100644 --- a/tests/test_lib/polyfill/test_polyfill.py +++ b/tests/test_lib/polyfill/test_polyfill.py @@ -166,3 +166,17 @@ def test_cells_to_geo(): assert coord[0][0] == coord[0][-1] assert h3.geo_to_cells(geo, res) == [h] + +def test_bad_geo_input(): + with pytest.raises(ValueError): + h3.h3shape_to_cells('not a shape', 9) + + with pytest.raises(ValueError): + h3.h3shape_to_cells_experimental('not a shape', res=9) + + with pytest.raises(ValueError): + h3.geo_to_cells({'type': 'not a shape', 'coordinates': None}, 9) + + # Add this new block to test our specific fix! + with pytest.raises(ValueError): + h3.geo_to_cells('not a shape', 9) From 631d8a6e435dba129363e1a2d8a21bb7a5bc70e7 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Thu, 27 Aug 2026 09:36:30 +0530 Subject: [PATCH 20/29] test: consolidate test_bad_geo_input to fix linter error --- tests/test_lib/polyfill/test_polyfill.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tests/test_lib/polyfill/test_polyfill.py b/tests/test_lib/polyfill/test_polyfill.py index 5f83be0..f70c639 100644 --- a/tests/test_lib/polyfill/test_polyfill.py +++ b/tests/test_lib/polyfill/test_polyfill.py @@ -151,6 +151,9 @@ def test_bad_geo_input(): with pytest.raises(ValueError): h3.geo_to_cells({'type': 'not a shape', 'coordinates': None}, 9) + with pytest.raises(ValueError): + h3.geo_to_cells('not a shape', 9) + def test_cells_to_geo(): h = '89754e64993ffff' @@ -166,17 +169,3 @@ def test_cells_to_geo(): assert coord[0][0] == coord[0][-1] assert h3.geo_to_cells(geo, res) == [h] - -def test_bad_geo_input(): - with pytest.raises(ValueError): - h3.h3shape_to_cells('not a shape', 9) - - with pytest.raises(ValueError): - h3.h3shape_to_cells_experimental('not a shape', res=9) - - with pytest.raises(ValueError): - h3.geo_to_cells({'type': 'not a shape', 'coordinates': None}, 9) - - # Add this new block to test our specific fix! - with pytest.raises(ValueError): - h3.geo_to_cells('not a shape', 9) From 47efd3266cb68f1efdc2baa832104f19057682f5 Mon Sep 17 00:00:00 2001 From: Conner Kupferberg Date: Tue, 22 Sep 2026 05:16:00 +0000 Subject: [PATCH 21/29] perf: bind scalar functions directly to _cy when _out_scalar is identity (#501) In h3.api.basic_int, numpy_int, and memview_int, _out_scalar is the identity function, incurring unnecessary Python function call frames and wrapper overhead on every scalar call. When _out_scalar is _in_scalar (integer-returning flavours), bind scalar functions directly to their _cy Cython implementations while preserving original docstrings and signatures. Eliminates ~18% (and up to 50%+ on ARM) latency on scalar calls. Fixes #501. --- src/h3/api/basic_int/__init__.py | 22 ++++++++++++++++++++ tests/test_lib/test_apis/test_basic_int.py | 22 ++++++++++++++++++++ tests/test_lib/test_apis/test_memview_int.py | 14 +++++++++++++ tests/test_lib/test_apis/test_numpy_int.py | 14 +++++++++++++ 4 files changed, 72 insertions(+) diff --git a/src/h3/api/basic_int/__init__.py b/src/h3/api/basic_int/__init__.py index ef82792..6ecf358 100644 --- a/src/h3/api/basic_int/__init__.py +++ b/src/h3/api/basic_int/__init__.py @@ -1365,3 +1365,25 @@ def is_valid_vertex(v): return _cy.is_valid_vertex(v) except (ValueError, TypeError): return False + + +if _out_scalar is _in_scalar: + # When _out_scalar is identity (basic_int, numpy_int, memview_int), + # bind scalar functions directly to their _cy counterparts to eliminate + # Python call frame and identity wrapper overhead (Issue #501). + for _name in ( + 'latlng_to_cell', + 'cell_to_parent', + 'cell_to_center_child', + 'cells_to_directed_edge', + 'get_directed_edge_origin', + 'get_directed_edge_destination', + 'directed_edge_to_cells', + 'local_ij_to_cell', + 'cell_to_vertex', + ): + _fn = globals()[_name] + _cy_fn = getattr(_cy, _name) + _cy_fn.__doc__ = _fn.__doc__ + globals()[_name] = _cy_fn + del _name, _fn, _cy_fn diff --git a/tests/test_lib/test_apis/test_basic_int.py b/tests/test_lib/test_apis/test_basic_int.py index a567b3d..3f3b14c 100644 --- a/tests/test_lib/test_apis/test_basic_int.py +++ b/tests/test_lib/test_apis/test_basic_int.py @@ -32,3 +32,25 @@ def test_compact_cells(): cells = h3.cell_to_children(h) assert h3.compact_cells(cells) == [h] + + +def test_identity_scalar_bindings(): + """ + Ensure scalar functions in int APIs are bound directly to _cy implementations + to eliminate wrapper and identity call overhead (Issue #501). + """ + from h3 import _cy + + assert h3.latlng_to_cell is _cy.latlng_to_cell + assert h3.cell_to_parent is _cy.cell_to_parent + assert h3.cell_to_center_child is _cy.cell_to_center_child + assert h3.cells_to_directed_edge is _cy.cells_to_directed_edge + assert h3.get_directed_edge_origin is _cy.get_directed_edge_origin + assert h3.get_directed_edge_destination is _cy.get_directed_edge_destination + assert h3.directed_edge_to_cells is _cy.directed_edge_to_cells + assert h3.local_ij_to_cell is _cy.local_ij_to_cell + assert h3.cell_to_vertex is _cy.cell_to_vertex + + # Ensure docstrings and signatures are intact + assert h3.latlng_to_cell.__doc__ is not None + assert 'latlng_to_cell' in h3.latlng_to_cell.__name__ diff --git a/tests/test_lib/test_apis/test_memview_int.py b/tests/test_lib/test_apis/test_memview_int.py index 0523794..f608f54 100644 --- a/tests/test_lib/test_apis/test_memview_int.py +++ b/tests/test_lib/test_apis/test_memview_int.py @@ -23,3 +23,17 @@ def test_line(): ] assert list(out) == expected + + +def test_identity_scalar_bindings(): + from h3 import _cy + + assert h3.latlng_to_cell is _cy.latlng_to_cell + assert h3.cell_to_parent is _cy.cell_to_parent + assert h3.cell_to_center_child is _cy.cell_to_center_child + assert h3.cells_to_directed_edge is _cy.cells_to_directed_edge + assert h3.get_directed_edge_origin is _cy.get_directed_edge_origin + assert h3.get_directed_edge_destination is _cy.get_directed_edge_destination + assert h3.directed_edge_to_cells is _cy.directed_edge_to_cells + assert h3.local_ij_to_cell is _cy.local_ij_to_cell + assert h3.cell_to_vertex is _cy.cell_to_vertex diff --git a/tests/test_lib/test_apis/test_numpy_int.py b/tests/test_lib/test_apis/test_numpy_int.py index c341b55..6bcd0b6 100644 --- a/tests/test_lib/test_apis/test_numpy_int.py +++ b/tests/test_lib/test_apis/test_numpy_int.py @@ -50,3 +50,17 @@ def test_numpy_str(): got = [h3.str_to_int(c) for c in cells] assert expected == got + + +def test_identity_scalar_bindings(): + from h3 import _cy + + assert h3.latlng_to_cell is _cy.latlng_to_cell + assert h3.cell_to_parent is _cy.cell_to_parent + assert h3.cell_to_center_child is _cy.cell_to_center_child + assert h3.cells_to_directed_edge is _cy.cells_to_directed_edge + assert h3.get_directed_edge_origin is _cy.get_directed_edge_origin + assert h3.get_directed_edge_destination is _cy.get_directed_edge_destination + assert h3.directed_edge_to_cells is _cy.directed_edge_to_cells + assert h3.local_ij_to_cell is _cy.local_ij_to_cell + assert h3.cell_to_vertex is _cy.cell_to_vertex From c0e89d0ff9e25e90a679d1da6bd01aac114e6983 Mon Sep 17 00:00:00 2001 From: kwy404 Date: Thu, 1 Oct 2026 18:48:06 -0300 Subject: [PATCH 22/29] fix: validate LatLngPoly loop length after dropping the closing point --- src/h3/_h3shape.py | 2 +- tests/test_lib/polyfill/test_polygon_class.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index a8146df..b778fd6 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -54,7 +54,7 @@ class LatLngPoly(H3Shape): def __init__(self, outer, *holes): loops = [outer] + list(holes) for loop in loops: - if len(loop) in (1, 2): + if len(loop) > 0 and len(_open_ring(loop)) < 3: raise ValueError('Non-empty LatLngPoly loops need at least 3 points.') point_dimensions = set(map(len, loop)) diff --git a/tests/test_lib/polyfill/test_polygon_class.py b/tests/test_lib/polyfill/test_polygon_class.py index 59e8da2..a3639b6 100644 --- a/tests/test_lib/polyfill/test_polygon_class.py +++ b/tests/test_lib/polyfill/test_polygon_class.py @@ -50,3 +50,16 @@ def test_bad_subclass(): with pytest.raises(ValueError): h3.h3shape_to_cells_experimental(shoop, res=9) + + +def test_closed_loop_with_too_few_points(): + # a closed loop of 3 points only has 2 distinct points once the + # repeated closing point is removed + a, b = (37.68, -122.54), (37.82, -122.34) + outer = [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34)] + + with pytest.raises(ValueError, match='at least 3 points'): + h3.LatLngPoly([a, b, a]) + + with pytest.raises(ValueError, match='at least 3 points'): + h3.LatLngPoly(outer, [a, b, a]) From 93b40427d04993957fc3820b401ed8e0652eb1cc Mon Sep 17 00:00:00 2001 From: Shaan Majid <70789625+shaanmajid@users.noreply.github.com> Date: Fri, 9 Oct 2026 17:49:47 -0700 Subject: [PATCH 23/29] Add CI test and build for Python 3.15 and 3.15t --- .github/workflows/tests.yml | 2 +- .github/workflows/wheels.yml | 20 +++++++++++++++++++- CHANGELOG.md | 1 + pyproject.toml | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f3dcc3c..f7a9854 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-22.04] - python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.14t'] + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.14t', '3.15', '3.15t'] steps: - uses: actions/checkout@v6.0.2 diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index b9bc985..1de5a80 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -83,6 +83,12 @@ jobs: - os: windows-11-arm build: 'cp314t-win_arm64' name: Windows ARM64 3.14t + - os: windows-11-arm + build: 'cp315-win_arm64' + name: Windows ARM64 3.15 + - os: windows-11-arm + build: 'cp315t-win_arm64' + name: Windows ARM64 3.15t - os: ubuntu-22.04 build: 'cp*-manylinux_x86_64' @@ -106,6 +112,12 @@ jobs: - os: ubuntu-22.04 build: 'cp314t-musllinux_x86_64' name: Linux Intel musl 64-bit 3.14t + - os: ubuntu-22.04 + build: 'cp315-musllinux_x86_64' + name: Linux Intel musl 64-bit 3.15 + - os: ubuntu-22.04 + build: 'cp315t-musllinux_x86_64' + name: Linux Intel musl 64-bit 3.15t - os: ubuntu-22.04 build: 'cp310-manylinux_aarch64' @@ -125,6 +137,12 @@ jobs: - os: ubuntu-22.04 build: 'cp314t-manylinux_aarch64' name: Linux Aarch64 3.14t + - os: ubuntu-22.04 + build: 'cp315-manylinux_aarch64' + name: Linux Aarch64 3.15 + - os: ubuntu-22.04 + build: 'cp315t-manylinux_aarch64' + name: Linux Aarch64 3.15t steps: - uses: actions/checkout@v6.0.2 @@ -158,7 +176,7 @@ jobs: with: platforms: aarch64 - - uses: pypa/cibuildwheel@v3.3.1 + - uses: pypa/cibuildwheel@v4.2.1 env: CIBW_BUILD_FRONTEND: 'build[uv]' CIBW_TEST_REQUIRES: pytest pytest-cov numpy diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ad11bf..9f23b02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ avoid adding features or APIs which do not map onto the ## Unreleased - Fix wheels for Python 3.14.6 free-threading +- Add Python 3.15 and 3.15t wheels ## [4.5.0] - 2026-05-29 diff --git a/pyproject.toml b/pyproject.toml index 2474f88..4430799 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ classifiers = [ 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: 3.13', 'Programming Language :: Python :: 3.14', + 'Programming Language :: Python :: 3.15', 'Programming Language :: Python :: Free Threading', 'Operating System :: MacOS :: MacOS X', 'Operating System :: POSIX :: Linux', From b19b0421fe4629479c14cf367db040730e6f1238 Mon Sep 17 00:00:00 2001 From: kwy404 Date: Sat, 10 Oct 2026 21:26:03 -0300 Subject: [PATCH 24/29] fix: return False from is_valid_* for indexes outside the uint64 range --- src/h3/api/basic_int/__init__.py | 8 ++++---- tests/test_lib/test_cells_and_edges.py | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/h3/api/basic_int/__init__.py b/src/h3/api/basic_int/__init__.py index ef82792..0c62a74 100644 --- a/src/h3/api/basic_int/__init__.py +++ b/src/h3/api/basic_int/__init__.py @@ -139,7 +139,7 @@ def is_valid_index(h): try: h = _in_scalar(h) return _cy.is_valid_index(h) - except (ValueError, TypeError): + except (ValueError, TypeError, OverflowError): return False @@ -154,7 +154,7 @@ def is_valid_cell(h): try: h = _in_scalar(h) return _cy.is_valid_cell(h) - except (ValueError, TypeError): + except (ValueError, TypeError, OverflowError): return False @@ -169,7 +169,7 @@ def is_valid_directed_edge(edge): try: e = _in_scalar(edge) return _cy.is_valid_directed_edge(e) - except (ValueError, TypeError): + except (ValueError, TypeError, OverflowError): return False @@ -1363,5 +1363,5 @@ def is_valid_vertex(v): try: v = _in_scalar(v) return _cy.is_valid_vertex(v) - except (ValueError, TypeError): + except (ValueError, TypeError, OverflowError): return False diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index 9b1907e..65d9d13 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -480,6 +480,14 @@ def test_edge_is_valid_fail(): assert not h3.is_valid_directed_edge(e_invalid) +def test_is_valid_out_of_uint64_range(): + for h in ['10000000000000000', '-1']: + assert not h3.is_valid_index(h) + assert not h3.is_valid_cell(h) + assert not h3.is_valid_directed_edge(h) + assert not h3.is_valid_vertex(h) + + def test_get_pentagons(): out = h3.get_pentagons(0) From f423ef9b8dff9f000cf257d91290a056fe32cf59 Mon Sep 17 00:00:00 2001 From: Sebastian Turner Date: Mon, 19 Oct 2026 15:56:52 -0700 Subject: [PATCH 25/29] Support rads units in average_hexagon_area and average_hexagon_edge_length Signed-off-by: Sebastian Turner --- CHANGELOG.md | 1 + src/h3/_cy/cells.pyx | 5 ++++- src/h3/_cy/edges.pyx | 5 ++++- src/h3/_cy/util.pyx | 4 ++++ tests/test_lib/test_length_area.py | 24 ++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f23b02..34856a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ avoid adding features or APIs which do not map onto the ## Unreleased - Fix wheels for Python 3.14.6 free-threading - Add Python 3.15 and 3.15t wheels +- Support `unit='rads'` in `average_hexagon_area` and `average_hexagon_edge_length` (#509) ## [4.5.0] - 2026-05-29 diff --git a/src/h3/_cy/cells.pyx b/src/h3/_cy/cells.pyx index 8b84f9d..f0667e5 100644 --- a/src/h3/_cy/cells.pyx +++ b/src/h3/_cy/cells.pyx @@ -8,6 +8,8 @@ from .util cimport ( check_distance, ) +from .util import EARTH_RADIUS_KM + from .error_system cimport ( H3Error, check_for_error, @@ -322,7 +324,8 @@ cpdef double average_hexagon_area(int resolution, unit='km^2') except -1: # todo: multiple units convert = { 'km^2': 1.0, - 'm^2': 1000*1000.0 + 'm^2': 1000*1000.0, + 'rads^2': 1.0/(EARTH_RADIUS_KM*EARTH_RADIUS_KM), } try: diff --git a/src/h3/_cy/edges.pyx b/src/h3/_cy/edges.pyx index 1d2ef74..7364bd5 100644 --- a/src/h3/_cy/edges.pyx +++ b/src/h3/_cy/edges.pyx @@ -4,6 +4,8 @@ from .h3lib cimport bool, H3int from .error_system cimport check_for_error +from .util import EARTH_RADIUS_KM + from .memory cimport H3MemoryManager # todo: make bint @@ -86,7 +88,8 @@ cpdef double average_hexagon_edge_length(int resolution, unit='km') except -1: # todo: multiple units convert = { 'km': 1.0, - 'm': 1000.0 + 'm': 1000.0, + 'rads': 1.0/EARTH_RADIUS_KM, } try: diff --git a/src/h3/_cy/util.pyx b/src/h3/_cy/util.pyx index 06823d0..74e8f80 100644 --- a/src/h3/_cy/util.pyx +++ b/src/h3/_cy/util.pyx @@ -19,6 +19,10 @@ from .error_system import ( H3IndexInvalidError, ) +# Must match EARTH_RADIUS_KM in h3lib's constants.h, which is not part of the +# public h3api.h header. Used to convert km based averages to radians. +EARTH_RADIUS_KM = 6371.007180918475 + cdef h3lib.LatLng deg2coord(double lat, double lng) nogil: cdef: h3lib.LatLng c diff --git a/tests/test_lib/test_length_area.py b/tests/test_lib/test_length_area.py index 1003f56..ca38257 100644 --- a/tests/test_lib/test_length_area.py +++ b/tests/test_lib/test_length_area.py @@ -86,6 +86,30 @@ def test_areas_at_00(): assert u.approx2(out, areas_rads2) +def test_average_hexagon_area_rads(): + # the ratio between km^2 and rads^2 should match the one used by cell_area + h = '89754e64993ffff' + ratio = h3.cell_area(h, unit='km^2') / h3.cell_area(h, unit='rads^2') + + for res in range(16): + km2 = h3.average_hexagon_area(res, unit='km^2') + rads2 = h3.average_hexagon_area(res, unit='rads^2') + + assert km2 / rads2 == pytest.approx(ratio) + + +def test_average_hexagon_edge_length_rads(): + # the ratio between km and rads should match the one used by edge_length + e = '139754e64993ffff' + ratio = h3.edge_length(e, unit='km') / h3.edge_length(e, unit='rads') + + for res in range(16): + km = h3.average_hexagon_edge_length(res, unit='km') + rads = h3.average_hexagon_edge_length(res, unit='rads') + + assert km / rads == pytest.approx(ratio) + + def test_bad_units(): h = '89754e64993ffff' e = '139754e64993ffff' From 1c84623b1222ee121c91937d73d6a7969bbe7c07 Mon Sep 17 00:00:00 2001 From: Sebastian Turner Date: Tue, 20 Oct 2026 16:47:26 -0700 Subject: [PATCH 26/29] Handle empty GeoJSON Polygon in geo_to_h3shape Signed-off-by: Sebastian Turner --- src/h3/_h3shape.py | 4 ++++ tests/test_lib/polyfill/test_h3.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index b778fd6..68d18c2 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -223,6 +223,10 @@ def _remove_z(ll1): def _LL2_to_polygon(ll2): + if len(ll2) == 0: + # empty GeoJSON Polygon, like `shapely.Polygon().__geo_interface__` + return LatLngPoly([]) + ll2 = [ _remove_z(ll1) for ll1 in ll2 diff --git a/tests/test_lib/polyfill/test_h3.py b/tests/test_lib/polyfill/test_h3.py index fed297f..3021fba 100644 --- a/tests/test_lib/polyfill/test_h3.py +++ b/tests/test_lib/polyfill/test_h3.py @@ -307,6 +307,18 @@ def test_geo_to_h3shape_rejects_non_dict(): h3.geo_to_h3shape('not a geo object') +def test_geo_to_h3shape_empty_polygon(): + # e.g., shapely.Polygon().__geo_interface__ + geo = MockGeoInterface({'type': 'Polygon', 'coordinates': ()}) + + shape = h3.geo_to_h3shape(geo) + assert isinstance(shape, h3.LatLngPoly) + assert shape.outer == () + assert shape.holes == () + + assert h3.geo_to_cells(geo, 9) == [] + + def test_polyfill_down_under(): sydney = [ (-33.8556, 151.1979), From 8db9a2f9626d5cf4d1f7cf936e040bf4d66ad845 Mon Sep 17 00:00:00 2001 From: kwy404 Date: Fri, 23 Oct 2026 17:40:02 -0300 Subject: [PATCH 27/29] fix: don't return a cell twice from h3shape_to_cells_experimental for a LatLngMultiPoly --- src/h3/_cy/latlng.pyx | 8 ++++++-- tests/test_lib/polyfill/test_h3.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/h3/_cy/latlng.pyx b/src/h3/_cy/latlng.pyx index 1593d43..630d3ad 100644 --- a/src/h3/_cy/latlng.pyx +++ b/src/h3/_cy/latlng.pyx @@ -262,11 +262,15 @@ def polygons_to_cells_experimental(polygons, int res, int flag): # probably super inefficient, but it is working! # tood: move this to C + # a cell can overlap more than one polygon, so skip the ones already added + seen = set() k = 0 for mv in mvs: for v in mv: - hmm.ptr[k] = v - k += 1 + if v not in seen: + seen.add(v) + hmm.ptr[k] = v + k += 1 return hmm.to_mv() diff --git a/tests/test_lib/polyfill/test_h3.py b/tests/test_lib/polyfill/test_h3.py index fed297f..a6966b9 100644 --- a/tests/test_lib/polyfill/test_h3.py +++ b/tests/test_lib/polyfill/test_h3.py @@ -207,6 +207,20 @@ def test_poly_to_cells_experimental_mpoly(): )) +def test_poly_to_cells_experimental_mpoly_no_duplicates(): + # cells that overlap both polygons should only be returned once + a = h3.LatLngPoly([(37.70, -122.50), (37.70, -122.45), (37.75, -122.45)]) + b = h3.LatLngPoly([(37.70, -122.449), (37.70, -122.40), (37.75, -122.40)]) + mpoly = h3.LatLngMultiPoly(a, b) + + out = h3.h3shape_to_cells_experimental(mpoly, res=7, contain='overlap') + + expected = set(h3.h3shape_to_cells_experimental(a, res=7, contain='overlap')) + expected |= set(h3.h3shape_to_cells_experimental(b, res=7, contain='overlap')) + assert len(out) == len(expected) + assert set(out) == expected + + def test_polyfill_with_hole(): poly = h3.LatLngPoly(sf_7x7, sf_hole1) From 9a26dc64775804a8b578fe07268124e098ccfa4a Mon Sep 17 00:00:00 2001 From: Jongbin Jung Date: Fri, 13 Nov 2026 14:02:49 -0800 Subject: [PATCH 28/29] Add missing items from changelog --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34856a9..0b6ee3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,15 @@ avoid adding features or APIs which do not map onto the ## Unreleased - Fix wheels for Python 3.14.6 free-threading -- Add Python 3.15 and 3.15t wheels +- Add Python 3.14t, 3.15 and 3.15t wheels - Support `unit='rads'` in `average_hexagon_area` and `average_hexagon_edge_length` (#509) +- Add `container` option to `h3shape_to_geo` (#495) +- Fix Android cross-compilation with Buildozer (#494) +- Raise `ValueError` instead of `assert` in `geo_to_h3shape` (#500, #502) +- Fix `LatLngPoly` loop length check for closed rings (#505) +- Return `False` from `is_valid_*` for out-of-range integers (#507) +- Handle empty GeoJSON Polygon in `geo_to_h3shape` (#511) +- Fix duplicate cells from `h3shape_to_cells_experimental` for `LatLngMultiPoly` (#512) ## [4.5.0] - 2026-05-29 From bec9b81090864db890ede0558104a5877df6ebdb Mon Sep 17 00:00:00 2001 From: Jongbin Jung Date: Fri, 13 Nov 2026 15:43:39 -0800 Subject: [PATCH 29/29] Exclude identity-binding block from coverage The block added in #504 only runs when `_out_scalar is _in_scalar`, which is true for basic_int, numpy_int, and memview_int, but not for basic_str. Coverage is only measured on the basic_str copy of the shared API file, so the block showed up as uncovered and failed the 100% coverage gate on master. Co-Authored-By: Claude Code --- src/h3/api/basic_int/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/h3/api/basic_int/__init__.py b/src/h3/api/basic_int/__init__.py index 6f36e77..8eac4b1 100644 --- a/src/h3/api/basic_int/__init__.py +++ b/src/h3/api/basic_int/__init__.py @@ -1367,10 +1367,13 @@ def is_valid_vertex(v): return False -if _out_scalar is _in_scalar: +if _out_scalar is _in_scalar: # pragma: no cover # When _out_scalar is identity (basic_int, numpy_int, memview_int), # bind scalar functions directly to their _cy counterparts to eliminate # Python call frame and identity wrapper overhead (Issue #501). + # + # Coverage is only measured on the basic_str copy of this file, where + # this branch is never taken; it is exercised by the int API tests. for _name in ( 'latlng_to_cell', 'cell_to_parent',