From e006cc3de88306ca20ea6e709fda7ec2e52c0a3c Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Sun, 26 Jan 2025 17:30:06 -0800 Subject: [PATCH 01/63] Update readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 4a8a4b5..1101c15 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ -H3 Logo - # **h3-py**: Uber's H3 Hexagonal Hierarchical Geospatial Indexing System in Python +H3 Logo + [![PyPI version](https://badge.fury.io/py/h3.svg)](https://badge.fury.io/py/h3) [![PyPI downloads](https://img.shields.io/pypi/dm/h3.svg)](https://pypistats.org/packages/h3) [![conda](https://img.shields.io/conda/vn/conda-forge/h3-py.svg)](https://anaconda.org/conda-forge/h3-py) From e054120e1b314289526b8a42e04b9658f2e19123 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Mon, 27 Jan 2025 11:38:18 -0800 Subject: [PATCH 02/63] Prep for v4.2.0 release (#438) * prep for v4.2.0 release * ensure you update the badge on the readme --- CHANGELOG.md | 6 +++++- dev_notes.md | 1 + readme.md | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6833583..9e66c98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,11 @@ avoid adding features or APIs which do not map onto the ## Unreleased -- Update to v4.2.0. (#432) +None. + +## [4.2.0] - 2025-01-26 + +- Update h3lib to v4.2.0. (#432) - Add `h3shape_to_cells_experimental` (#436) - Add `polygon_to_cells_experimental` alias diff --git a/dev_notes.md b/dev_notes.md index 71d514d..300ee42 100644 --- a/dev_notes.md +++ b/dev_notes.md @@ -49,6 +49,7 @@ git submodule update --init - update `CHANGELOG.md` to reflect any changes since the last release - update the `h3-py` version in `pyproject.toml` +- if updating the C `h3lib` version, update the version badge on the readme - create PR, get reviews, and merge with these changes - go to https://github.com/uber/h3-py/releases and "Draft a new release" - set the tag version and the release to the version. e.g., `v3.7.2` diff --git a/readme.md b/readme.md index 4a8a4b5..d37f1a4 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ [![PyPI version](https://badge.fury.io/py/h3.svg)](https://badge.fury.io/py/h3) [![PyPI downloads](https://img.shields.io/pypi/dm/h3.svg)](https://pypistats.org/packages/h3) [![conda](https://img.shields.io/conda/vn/conda-forge/h3-py.svg)](https://anaconda.org/conda-forge/h3-py) -[![version](https://img.shields.io/badge/h3-v4.1.0-blue.svg)](https://github.com/uber/h3/releases/tag/v4.1.0) +[![version](https://img.shields.io/badge/h3-v4.2.0-blue.svg)](https://github.com/uber/h3/releases/tag/v4.2.0) [![version](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/uber/h3-py/blob/master/LICENSE) [![Tests](https://github.com/uber/h3-py/workflows/tests/badge.svg)](https://github.com/uber/h3-py/actions) From ea05321c1d732527e64d9887b5e28fdfc2f4b3bb Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Thu, 30 Jan 2025 13:41:06 -0800 Subject: [PATCH 03/63] Fix pyproject.toml links --- pyproject.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 06ce0e3..8415a41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,11 +38,11 @@ classifiers = [ ] [project.urls] -Homepage = 'https://github.com/organization/package' -Documentation = 'https://package.readthedocs.io/' -'Bug Tracker' = 'https://github.com/organization/package/issues' -Discussions = 'https://github.com/organization/package/discussions' -Changelog = 'https://package.readthedocs.io/en/latest/changelog.html' +Homepage = 'https://github.com/uber/h3-py' +Documentation = 'https://uber.github.io/h3-py/' +'Bug Tracker' = 'https://github.com/uber/h3-py/issues' +Discussions = 'https://github.com/uber/h3-py/discussions' +Changelog = 'https://uber.github.io/h3-py/_changelog.html' [project.optional-dependencies] From e02cd4f4f96c0dde35083de206a6d41db82596c0 Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Thu, 30 Jan 2025 20:49:51 -0800 Subject: [PATCH 04/63] Update coverage badge in readme.md Fixes #439 --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index d37f1a4..e50dbfa 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ [![version](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/uber/h3-py/blob/master/LICENSE) [![Tests](https://github.com/uber/h3-py/workflows/tests/badge.svg)](https://github.com/uber/h3-py/actions) -[![codecov](https://codecov.io/gh/uber/h3-py/branch/master/graph/badge.svg)](https://codecov.io/gh/uber/h3-py) +[![Coverage 100%](https://img.shields.io/badge/coverage-100%25-green.svg)](https://github.com/uber/h3-py/blob/master/.github/workflows/lint_and_coverage.yml#L31) Python bindings for the [H3 core library](https://h3geo.org/). From ae375a987c107b5bc2b4315db7d8957ede9ea026 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Fri, 31 Jan 2025 14:32:21 -0800 Subject: [PATCH 05/63] fix links (#444) --- CHANGELOG.md | 5 +++++ pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e66c98..e9a29bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ avoid adding features or APIs which do not map onto the None. +## [4.2.1] - 2025-01-31 + +- Correct pyproject.toml links for PyPI (#441) +- Update coverage badge (#443) + ## [4.2.0] - 2025-01-26 - Update h3lib to v4.2.0. (#432) diff --git a/pyproject.toml b/pyproject.toml index 8415a41..eee5951 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.2.0' +version = '4.2.1' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} From b40bc47f779bf6e0759b926dba783be2a340b6c6 Mon Sep 17 00:00:00 2001 From: Sukhdeep Gill Date: Sat, 22 Feb 2025 22:46:42 +0530 Subject: [PATCH 06/63] reducing width for the H3 Logo so that it comes before the horizontal line (#447) --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e50dbfa..9a84445 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -H3 Logo +H3 Logo # **h3-py**: Uber's H3 Hexagonal Hierarchical Geospatial Indexing System in Python From 5b6382d12071fae93db19eeec888ff9742a9d33d Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Mon, 10 Mar 2025 09:27:55 -0700 Subject: [PATCH 07/63] bump to h3 4.2.1 (#450) --- readme.md | 2 +- src/h3lib | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 9a84445..c6cabd6 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ [![PyPI version](https://badge.fury.io/py/h3.svg)](https://badge.fury.io/py/h3) [![PyPI downloads](https://img.shields.io/pypi/dm/h3.svg)](https://pypistats.org/packages/h3) [![conda](https://img.shields.io/conda/vn/conda-forge/h3-py.svg)](https://anaconda.org/conda-forge/h3-py) -[![version](https://img.shields.io/badge/h3-v4.2.0-blue.svg)](https://github.com/uber/h3/releases/tag/v4.2.0) +[![version](https://img.shields.io/badge/h3-v4.2.1-blue.svg)](https://github.com/uber/h3/releases/tag/v4.2.1) [![version](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/uber/h3-py/blob/master/LICENSE) [![Tests](https://github.com/uber/h3-py/workflows/tests/badge.svg)](https://github.com/uber/h3-py/actions) diff --git a/src/h3lib b/src/h3lib index 2d8a62d..067d9c7 160000 --- a/src/h3lib +++ b/src/h3lib @@ -1 +1 @@ -Subproject commit 2d8a62d5fe456bba2af7ca0be7efe9754f1dd25b +Subproject commit 067d9c7d80061118e953fa682e56e49f571fa7a1 From 856d481de31c54aaa6076020ade6b88ed4d316cc Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Mon, 10 Mar 2025 11:30:25 -0700 Subject: [PATCH 08/63] prep for v4.2.2 release (#451) --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9a29bd..4f57f92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ avoid adding features or APIs which do not map onto the None. +## [4.2.2] - 2025-03-10 + +- Update h3lib to v4.2.1. (#450) + ## [4.2.1] - 2025-01-31 - Correct pyproject.toml links for PyPI (#441) diff --git a/pyproject.toml b/pyproject.toml index eee5951..38e4c91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.2.1' +version = '4.2.2' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} From e2744ccbcf25d4d93cab9d858a5bcb3edb03db21 Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Tue, 17 Jun 2025 16:57:21 -0500 Subject: [PATCH 09/63] update for h3 4.3.0 --- CHANGELOG.md | 2 +- src/h3/_cy/cells.pyx | 44 ++++---------------------------------------- src/h3lib | 2 +- 3 files changed, 6 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f57f92..2e5154f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ avoid adding features or APIs which do not map onto the ## Unreleased -None. +- Update h3lib to v4.3.0. (#) ## [4.2.2] - 2025-03-10 diff --git a/src/h3/_cy/cells.pyx b/src/h3/_cy/cells.pyx index 2b57af2..928b665 100644 --- a/src/h3/_cy/cells.pyx +++ b/src/h3/_cy/cells.pyx @@ -87,41 +87,6 @@ cpdef H3int[:] grid_disk(H3int h, int k): return mv -cpdef H3int[:] _ring_fallback(H3int h, int k): - """ - `ring` tries to call `h3lib.hexRing` first; if that fails, we call - this function, which relies on `h3lib.kRingDistances`. - - Failures for `h3lib.hexRing` happen when the algorithm runs into a pentagon. - """ - cdef: - int64_t n - int[:] distances ## todo: weird, this needs to be specified to avoid errors. cython bug? - - check_cell(h) - check_distance(k) - - check_for_error( - h3lib.maxGridDiskSize(k, &n) - ) - hmm = H3MemoryManager(n) - - # parallel array of cell distances from `h`. - # idea: instead of a memoryview object, have a my_mv object that can return a ptr, but does the correct logic when it has length 0 - # then can always just return the pointer, instead of the weird &mv[0] syntax - distances = int_mv(n) - check_for_error( - h3lib.gridDiskDistances(h, k, hmm.ptr, &distances[0]) - ) - - for i,v in enumerate(distances): - if v != k: - hmm.ptr[i] = 0 - - mv = hmm.to_mv() - - return mv - cpdef H3int[:] grid_ring(H3int h, int k): """ Return cells at grid distance `== k` from `h`. Collection is "hollow" for k >= 1. @@ -131,11 +96,10 @@ cpdef H3int[:] grid_ring(H3int h, int k): n = 6*k if k > 0 else 1 hmm = H3MemoryManager(n) - err = h3lib.gridRingUnsafe(h, k, hmm.ptr) - if err: - mv = _ring_fallback(h, k) - else: - mv = hmm.to_mv() + check_for_error( + h3lib.gridRing(h, k, hmm.ptr) + ) + mv = hmm.to_mv() return mv diff --git a/src/h3lib b/src/h3lib index 067d9c7..f6d1b0b 160000 --- a/src/h3lib +++ b/src/h3lib @@ -1 +1 @@ -Subproject commit 067d9c7d80061118e953fa682e56e49f571fa7a1 +Subproject commit f6d1b0ba0a0eb076abe655ffdd576a445373a39e From e80494c8ea98af03afa9b3b8db456f7266dec3ca Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Tue, 17 Jun 2025 16:57:55 -0500 Subject: [PATCH 10/63] readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c6cabd6..1a82d89 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ [![PyPI version](https://badge.fury.io/py/h3.svg)](https://badge.fury.io/py/h3) [![PyPI downloads](https://img.shields.io/pypi/dm/h3.svg)](https://pypistats.org/packages/h3) [![conda](https://img.shields.io/conda/vn/conda-forge/h3-py.svg)](https://anaconda.org/conda-forge/h3-py) -[![version](https://img.shields.io/badge/h3-v4.2.1-blue.svg)](https://github.com/uber/h3/releases/tag/v4.2.1) +[![version](https://img.shields.io/badge/h3-v4.3.0-blue.svg)](https://github.com/uber/h3/releases/tag/v4.3.0) [![version](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/uber/h3-py/blob/master/LICENSE) [![Tests](https://github.com/uber/h3-py/workflows/tests/badge.svg)](https://github.com/uber/h3-py/actions) From f82581f512a3f516eafe7261ff9e4f88b3107192 Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Tue, 17 Jun 2025 16:58:26 -0500 Subject: [PATCH 11/63] pr number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e5154f..fb995e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ avoid adding features or APIs which do not map onto the ## Unreleased -- Update h3lib to v4.3.0. (#) +- Update h3lib to v4.3.0. (#461) ## [4.2.2] - 2025-03-10 From 45d9c3f48273c2d84aa63f83d716c2a2207cabd7 Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Tue, 17 Jun 2025 17:50:19 -0500 Subject: [PATCH 12/63] fix --- src/h3/_cy/h3lib.pxd | 1 + 1 file changed, 1 insertion(+) diff --git a/src/h3/_cy/h3lib.pxd b/src/h3/_cy/h3lib.pxd index 4a483b2..e94f655 100644 --- a/src/h3/_cy/h3lib.pxd +++ b/src/h3/_cy/h3lib.pxd @@ -139,6 +139,7 @@ cdef extern from 'h3api.h': H3Error localIjToCell(H3int origin, const CoordIJ *ij, uint32_t mode, H3int *out) nogil H3Error gridDiskDistances(H3int origin, int k, H3int *out, int *distances) nogil + H3Error gridRing(H3int origin, int k, H3int *out) nogil H3Error gridRingUnsafe(H3int origin, int k, H3int *out) nogil H3Error areNeighborCells(H3int origin, H3int destination, int *out) nogil From a8c5ae7b279b80c6f37ff7e944a136a84829b6f2 Mon Sep 17 00:00:00 2001 From: Isaac Brodsky Date: Tue, 17 Jun 2025 17:52:00 -0500 Subject: [PATCH 13/63] fix version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 38e4c91..8e77163 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.2.2' +version = '4.3.0' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} From ce0638d7cedb034a7b533e875e996da88a2a7268 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Wed, 18 Jun 2025 09:20:22 -0700 Subject: [PATCH 14/63] prep for 4.3.0 release (#462) --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb995e7..8cbc3f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,10 @@ avoid adding features or APIs which do not map onto the ## Unreleased -- Update h3lib to v4.3.0. (#461) +## [4.3.0] - 2025-06-17 + +- Update `h3lib` to v4.3.0. (#461) + - Uses `gridRing` (uber/h3#1016) instead of Cython fallback logic. ## [4.2.2] - 2025-03-10 From 4fc8ec9ca683856e97cd3dc9822c40bd229756af Mon Sep 17 00:00:00 2001 From: newyork_loki <137760120+lowkeyrossi@users.noreply.github.com> Date: Mon, 11 Aug 2025 00:04:06 +0530 Subject: [PATCH 15/63] Add support for building h3-py wheel on WoA (#463) * Add support for building h3-py wheel on WoA * Use official MSVC reusable action for Win-builds --- .github/workflows/wheels.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index c70b891..99e81d1 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -71,6 +71,16 @@ jobs: build: 'cp3*-win_amd64' name: Windows 64-bit + - os: windows-11-arm + build: 'cp311-win_arm64' + name: Windows ARM64 3.11 + - os: windows-11-arm + build: 'cp312-win_arm64' + name: Windows ARM64 3.12 + - os: windows-11-arm + build: 'cp313-win_arm64' + name: Windows ARM64 3.13 + - os: ubuntu-22.04 build: 'cp*-manylinux_x86_64' name: Linux Intel glibc 64-bit @@ -118,8 +128,17 @@ jobs: with: submodules: recursive - - uses: ilammy/msvc-dev-cmd@v1.13.0 - if: runner.os == 'Windows' + - name: Set MSVC for Windows-x64 + uses: microsoft/setup-msbuild@v2 + if: matrix.os == 'windows-latest' + with: + msbuild-architecture: x64 + + - name: Set MSVC for Windows-ARM64 + uses: microsoft/setup-msbuild@v2 + if: matrix.os == 'windows-11-arm' + with: + msbuild-architecture: arm64 - name: Set Windows variables if: runner.os == 'Windows' @@ -134,7 +153,7 @@ jobs: with: platforms: aarch64 - - uses: pypa/cibuildwheel@v2.21.3 + - uses: pypa/cibuildwheel@v3.1.3 env: CIBW_TEST_REQUIRES: pytest pytest-cov numpy CIBW_TEST_COMMAND: pytest {project}/tests From bd455be97581f0abd8d1afed41e0be066cf51e9a Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Sun, 10 Aug 2025 12:30:56 -0700 Subject: [PATCH 16/63] prep for v4.3.1 release (#464) --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cbc3f0..77fc091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,12 @@ avoid adding features or APIs which do not map onto the ## Unreleased +None. + +## [4.3.1] - 2025-08-10 + +- Build wheels for Windows on ARM64 (#463) + ## [4.3.0] - 2025-06-17 - Update `h3lib` to v4.3.0. (#461) diff --git a/pyproject.toml b/pyproject.toml index 8e77163..9f88ce8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.3.0' +version = '4.3.1' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} From 99b62102b0c72113a6416a7c6407ba4ee1deb1da Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Oct 2025 16:46:17 -0700 Subject: [PATCH 17/63] Bump pypa/gh-action-pypi-publish in /.github/workflows (#466) Bumps [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) from 1.10.3 to 1.13.0. - [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases) - [Commits](https://github.com/pypa/gh-action-pypi-publish/compare/v1.10.3...v1.13.0) --- updated-dependencies: - dependency-name: pypa/gh-action-pypi-publish dependency-version: 1.13.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 99e81d1..e93afab 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -194,6 +194,6 @@ jobs: name: wheels_and_sdist path: dist - - uses: pypa/gh-action-pypi-publish@v1.10.3 + - uses: pypa/gh-action-pypi-publish@v1.13.0 with: password: ${{ secrets.pypi_password }} From 23bef19c74e5332216f079b156aa8ca196e37ec0 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Sun, 2 Nov 2025 08:23:06 -0800 Subject: [PATCH 18/63] remove macOS13 from wheels. add macOS15 (#468) * remove macOS13 from wheels. add macOS15 * bump to pypa/cibuildwheel@v3.2.1 * bump actions/setup-python@v6.0.0 * bump actions/upload-artifact@v5.0.0 * bump actions/checkout@v5.0.0 * bump actions/download-artifact@v6.0.0 * bump docker/setup-qemu-action@v3.6.0 * run tests on Python 3.14 * Add a few wheels for Python 3.14 * bump python-version: 3.13 * Revert "bump python-version: 3.13" This reverts commit 8119c62cb60d70b38cf42206c755ce7a6e408716. --- .github/workflows/build_docs.yml | 6 ++--- .github/workflows/lint_and_coverage.yml | 4 +-- .github/workflows/tests.yml | 6 ++--- .github/workflows/wheels.yml | 33 ++++++++++++++++--------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index f6c950c..f8301d1 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v5.0.0 with: submodules: recursive - - uses: actions/setup-python@v5.3.0 + - uses: actions/setup-python@v6.0.0 with: python-version: 3.11 @@ -28,7 +28,7 @@ jobs: run: jupyter-book build docs/ --warningiserror --keep-going --all - name: Upload artifacts - uses: actions/upload-artifact@v4.4.3 + uses: actions/upload-artifact@v5.0.0 with: name: html path: docs/_build/html diff --git a/.github/workflows/lint_and_coverage.yml b/.github/workflows/lint_and_coverage.yml index 723677c..d9789c7 100644 --- a/.github/workflows/lint_and_coverage.yml +++ b/.github/workflows/lint_and_coverage.yml @@ -12,11 +12,11 @@ jobs: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5.0.0 with: submodules: recursive - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v6.0.0 with: python-version: 3.11 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cd4153d..a82ec98 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,14 +14,14 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-22.04] - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] steps: - - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v5.0.0 with: submodules: recursive - - uses: actions/setup-python@v5.3.0 + - uses: actions/setup-python@v6.0.0 with: python-version: '${{ matrix.python-version }}' diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index e93afab..cde27d7 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -23,12 +23,12 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v5.0.0 with: submodules: recursive - name: Setup Python - uses: actions/setup-python@v5.3.0 + uses: actions/setup-python@v6.0.0 with: python-version: 3.11 @@ -48,7 +48,7 @@ jobs: run: pytest - name: Upload artifacts to GitHub - uses: actions/upload-artifact@v4.4.3 + uses: actions/upload-artifact@v5.0.0 with: name: temp_result_sdist path: ./dist @@ -60,12 +60,12 @@ jobs: strategy: matrix: include: - - os: macos-13 - build: 'cp*-macosx_x86_64' - name: macOS13 - os: macos-14 build: 'cp*-macosx_arm64' name: macOS14 + - os: macos-15 + build: 'cp*-macosx_arm64' + name: macOS15 - os: windows-latest build: 'cp3*-win_amd64' @@ -80,6 +80,9 @@ jobs: - os: windows-11-arm build: 'cp313-win_arm64' name: Windows ARM64 3.13 + - os: windows-11-arm + build: 'cp314-win_arm64' + name: Windows ARM64 3.14 - os: ubuntu-22.04 build: 'cp*-manylinux_x86_64' @@ -103,6 +106,9 @@ jobs: - os: ubuntu-22.04 build: 'cp313-musllinux_x86_64' name: Linux Intel musl 64-bit 3.13 + - os: ubuntu-22.04 + build: 'cp314-musllinux_x86_64' + name: Linux Intel musl 64-bit 3.14 - os: ubuntu-22.04 build: 'cp38-manylinux_aarch64' @@ -122,9 +128,12 @@ jobs: - os: ubuntu-22.04 build: 'cp313-manylinux_aarch64' name: Linux Aarch64 3.13 + - os: ubuntu-22.04 + build: 'cp314-manylinux_aarch64' + name: Linux Aarch64 3.14 steps: - - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v5.0.0 with: submodules: recursive @@ -149,11 +158,11 @@ jobs: - name: Set up QEMU if: runner.os == 'Linux' - uses: docker/setup-qemu-action@v3.2.0 + uses: docker/setup-qemu-action@v3.6.0 with: platforms: aarch64 - - uses: pypa/cibuildwheel@v3.1.3 + - uses: pypa/cibuildwheel@v3.2.1 env: CIBW_TEST_REQUIRES: pytest pytest-cov numpy CIBW_TEST_COMMAND: pytest {project}/tests @@ -165,7 +174,7 @@ jobs: pipx run twine check wheelhouse/* - name: Upload artifacts to GitHub - uses: actions/upload-artifact@v4.4.3 + uses: actions/upload-artifact@v5.0.0 with: name: temp_result_${{ matrix.os }}-${{ strategy.job-index }} path: wheelhouse/*.whl @@ -175,7 +184,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Merge Artifacts - uses: actions/upload-artifact/merge@v4.4.3 + uses: actions/upload-artifact/merge@v5.0.0 with: name: wheels_and_sdist pattern: temp_result_* @@ -189,7 +198,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v4.1.8 + - uses: actions/download-artifact@v6.0.0 with: name: wheels_and_sdist path: dist From f9c1a944d1be1c78e713939c00a70c60dd5219bc Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Sat, 22 Nov 2025 08:17:21 -0800 Subject: [PATCH 19/63] Bump h3lib to v4.4.1 and add new functions/errors (#470) * bump h3lib to v4.4.0 * bump h3lib to v4.4.1 * tests pass with new version * add new error codes and some helper functions around error codes * jupyter-book<2 * is_valid_index * tests for is_valid_index and get_index_digit * linting * good set of tests * lint * thank you, coverage tests for tests! * int api test * function docstrings * maybe not * changelog. don't expose error code helper functions (yet) * ticks * don't even mention 'em * `list` rather than `tuple`, since users are likely to mutate result * remove justfile * failing tests * tests should be passing * more tests * swap docs order --- .gitignore | 1 + CHANGELOG.md | 12 +- docs/api_quick.md | 4 + pyproject.toml | 4 +- src/h3/__init__.py | 4 + src/h3/_cy/__init__.py | 10 ++ src/h3/_cy/cells.pxd | 3 + src/h3/_cy/cells.pyx | 38 +++++- src/h3/_cy/error_system.pxd | 3 + src/h3/_cy/error_system.pyx | 37 +++++- src/h3/_cy/h3lib.pxd | 8 ++ src/h3/_cy/util.pxd | 3 +- src/h3/_cy/util.pyx | 16 ++- src/h3/api/basic_int/__init__.py | 129 +++++++++++++++++++++ src/h3lib | 2 +- tests/test_lib/test_cells_and_edges.py | 154 +++++++++++++++++++++++++ tests/test_lib/test_error_codes.py | 42 ++++--- 17 files changed, 442 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index ad8e4f3..cf6fcf3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ h3c/ .cache/ h3/out/ .ruff_cache/ +_build/ # Generated C code from Cython test tests/**/*.c diff --git a/CHANGELOG.md b/CHANGELOG.md index 77fc091..5349789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,17 @@ avoid adding features or APIs which do not map onto the ## Unreleased -None. +- Update `h3lib` to v4.4.1. (#470) + - Add new error codes: + - `H3IndexInvalidError` + - `H3BaseCellDomainError` + - `H3DigitDomainError` + - `H3DeletedDigitError` + - Add new functions: + - `is_valid_index` + - `get_index_digit` + - `construct_cell` + - `deconstruct_cell` ## [4.3.1] - 2025-08-10 diff --git a/docs/api_quick.md b/docs/api_quick.md index 7b29638..6694ed4 100644 --- a/docs/api_quick.md +++ b/docs/api_quick.md @@ -25,6 +25,7 @@ and should be generally aligned with the is_res_class_III is_valid_directed_edge is_valid_vertex + is_valid_index ``` ## Index representation @@ -49,6 +50,9 @@ and should be generally aligned with the get_num_cells get_resolution get_base_cell_number + get_index_digit + construct_cell + deconstruct_cell ``` ## Geographic coordinates diff --git a/pyproject.toml b/pyproject.toml index 9f88ce8..4a5e319 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.3.1' +version = '4.4.0' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} @@ -50,7 +50,7 @@ numpy = ['numpy'] test = ['pytest', 'pytest-cov', 'ruff', 'numpy'] all = [ 'h3[test]', - 'jupyter-book', + 'jupyter-book<2', 'sphinx>=7.3.3', # https://github.com/sphinx-doc/sphinx/issues/12290 'jupyterlab', 'jupyterlab-geojson', diff --git a/src/h3/__init__.py b/src/h3/__init__.py index 4f7cb32..1e4f4b8 100644 --- a/src/h3/__init__.py +++ b/src/h3/__init__.py @@ -26,4 +26,8 @@ from ._cy import ( H3MemoryAllocError, H3MemoryBoundsError, H3OptionInvalidError, + H3IndexInvalidError, + H3BaseCellDomainError, + H3DigitDomainError, + H3DeletedDigitError, ) diff --git a/src/h3/_cy/__init__.py b/src/h3/_cy/__init__.py index 627f3b9..70fa087 100644 --- a/src/h3/_cy/__init__.py +++ b/src/h3/_cy/__init__.py @@ -14,10 +14,13 @@ function interface and input conversion (string to int, for instance). """ from .cells import ( + is_valid_index, is_valid_cell, is_pentagon, get_base_cell_number, get_resolution, + get_index_digit, + construct_cell, cell_to_parent, grid_distance, grid_disk, @@ -109,4 +112,11 @@ from .error_system import ( H3MemoryAllocError, H3MemoryBoundsError, H3OptionInvalidError, + H3IndexInvalidError, + H3BaseCellDomainError, + H3DigitDomainError, + H3DeletedDigitError, + + get_H3_ERROR_END, + error_code_to_exception, ) diff --git a/src/h3/_cy/cells.pxd b/src/h3/_cy/cells.pxd index 06b35ee..1bc31b8 100644 --- a/src/h3/_cy/cells.pxd +++ b/src/h3/_cy/cells.pxd @@ -1,9 +1,12 @@ from .h3lib cimport bool, int64_t, H3int +cpdef bool is_valid_index(H3int h) cpdef bool is_valid_cell(H3int h) cpdef bool is_pentagon(H3int h) cpdef int get_base_cell_number(H3int h) except -1 cpdef int get_resolution(H3int h) except -1 +cpdef int get_index_digit(H3int h, int res) except -1 +cpdef H3int construct_cell(int baseCellNumber, const int[:] digits) except 0 cpdef int grid_distance(H3int h1, H3int h2) except -1 cpdef H3int[:] grid_disk(H3int h, int k) cpdef H3int[:] grid_ring(H3int h, int k) diff --git a/src/h3/_cy/cells.pyx b/src/h3/_cy/cells.pyx index 928b665..78d2561 100644 --- a/src/h3/_cy/cells.pyx +++ b/src/h3/_cy/cells.pyx @@ -3,11 +3,12 @@ from .h3lib cimport bool, int64_t, H3int, H3ErrorCodes from .util cimport ( check_cell, - check_res, # we don't use? + check_index, check_distance, ) from .error_system cimport ( + H3Error, check_for_error, check_for_error_msg, ) @@ -19,6 +20,14 @@ from .memory cimport ( # todo: add notes about Cython exception handling +cpdef bool is_valid_index(H3int h): + """Validates an H3 index (cell, vertex, or directed edge). + + Returns + ------- + boolean + """ + return h3lib.isValidIndex(h) == 1 # bool is a python type, so we don't need the except clause cpdef bool is_valid_cell(H3int h): @@ -49,6 +58,33 @@ cpdef int get_resolution(H3int h) except -1: return h3lib.getResolution(h) +cpdef int get_index_digit(H3int h, int res) except -1: + cdef: + int digit + + check_index(h) + + check_for_error( + h3lib.getIndexDigit(h, res, &digit) + ) + + return digit + +cpdef H3int construct_cell(int base_cell_number, const int[:] digits) except 0: + cdef: + H3int out + int res = len(digits) + H3Error err + + if res > 0: + err = h3lib.constructCell(res, base_cell_number, &digits[0], &out) + else: + err = h3lib.constructCell(res, base_cell_number, NULL, &out) + + check_for_error(err) + + return out + cpdef int grid_distance(H3int h1, H3int h2) except -1: """ Compute the grid distance between two cells diff --git a/src/h3/_cy/error_system.pxd b/src/h3/_cy/error_system.pxd index af8c709..4a1e3b4 100644 --- a/src/h3/_cy/error_system.pxd +++ b/src/h3/_cy/error_system.pxd @@ -1,3 +1,6 @@ from .h3lib cimport H3Error + +cpdef error_code_to_exception(H3Error err) cdef check_for_error(H3Error err) cdef check_for_error_msg(H3Error err, str msg) +cpdef H3Error get_H3_ERROR_END() diff --git a/src/h3/_cy/error_system.pyx b/src/h3/_cy/error_system.pyx index fbdd918..fc18f46 100644 --- a/src/h3/_cy/error_system.pyx +++ b/src/h3/_cy/error_system.pyx @@ -60,6 +60,10 @@ Summarizing, all exceptions originating from the C library inherit from - H3MemoryAllocError - H3MemoryBoundsError - H3OptionInvalidError +- H3IndexInvalidError +- H3BaseCellDomainError +- H3DigitDomainError +- H3DeletedDigitError # TODO: add tests verifying that concrete exception classes have the right error codes associated with them @@ -87,6 +91,11 @@ from .h3lib cimport ( E_MEMORY_ALLOC, E_MEMORY_BOUNDS, E_OPTION_INVALID, + E_INDEX_INVALID, + E_BASE_CELL_DOMAIN, + E_DIGIT_DOMAIN, + E_DELETED_DIGIT, + H3_ERROR_END # sentinel value ) @contextmanager @@ -169,6 +178,10 @@ with _the_error(H3ValueError) as e: class H3NotNeighborsError(e): ... class H3ResMismatchError(e): ... class H3OptionInvalidError(e): ... + class H3IndexInvalidError(e): ... + class H3BaseCellDomainError(e): ... + class H3DigitDomainError(e): ... + class H3DeletedDigitError(e): ... """ @@ -192,6 +205,10 @@ error_mapping = { E_MEMORY_ALLOC: H3MemoryAllocError, E_MEMORY_BOUNDS: H3MemoryBoundsError, E_OPTION_INVALID: H3OptionInvalidError, + E_INDEX_INVALID: H3IndexInvalidError, + E_BASE_CELL_DOMAIN: H3BaseCellDomainError, + E_DIGIT_DOMAIN: H3DigitDomainError, + E_DELETED_DIGIT: H3DeletedDigitError, } # Go back and modify the class definitions so that each concrete exception @@ -207,25 +224,37 @@ for code, ex in error_mapping.items(): # TODO: Move the helpers to util? # TODO: Unclear how/where to expose these functions. cdef/cpdef? -cdef code_to_exception(H3Error err): +cpdef error_code_to_exception(H3Error err): + """ + Return Python exception corresponding to integer error code + given via the H3ErrorCodes enum in `h3api.h.in` in the C library. + """ if err == E_SUCCESS: return None elif err in error_mapping: return error_mapping[err] else: - raise UnknownH3ErrorCode(err) + return UnknownH3ErrorCode(err) cdef check_for_error(H3Error err): - ex = code_to_exception(err) + ex = error_code_to_exception(err) if ex: raise ex +cpdef H3Error get_H3_ERROR_END(): + """ + Return integer H3_ERROR_END from the H3ErrorCodes enum + in `h3api.h.in` in the C library, which is one greater than + the last valid error code. + """ + return H3_ERROR_END + # todo: There's no easy way to do `*args` in `cdef` functions, but I'm also # not sure this even needs to be a Cython `cdef` function at all, or that # any of the other helper functions need to be in Cython. # todo: Revisit after we've played with this a bit. # todo: also: maybe the extra messages aren't that much more helpful... cdef check_for_error_msg(H3Error err, str msg): - ex = code_to_exception(err) + ex = error_code_to_exception(err) if ex: raise ex(msg) diff --git a/src/h3/_cy/h3lib.pxd b/src/h3/_cy/h3lib.pxd index e94f655..8cf74a7 100644 --- a/src/h3/_cy/h3lib.pxd +++ b/src/h3/_cy/h3lib.pxd @@ -29,6 +29,11 @@ cdef extern from 'h3api.h': E_MEMORY_ALLOC = 13 E_MEMORY_BOUNDS = 14 E_OPTION_INVALID = 15 + E_INDEX_INVALID = 16 + E_BASE_CELL_DOMAIN = 17 + E_DIGIT_DOMAIN = 18 + E_DELETED_DIGIT = 19 + H3_ERROR_END # sentinel value ctypedef struct LatLng: double lat # in radians @@ -71,12 +76,15 @@ cdef extern from 'h3api.h': int isResClassIII(H3int h) nogil int isValidDirectedEdge(H3int edge) nogil int isValidVertex(H3int v) nogil + int isValidIndex(H3int h) nogil double degsToRads(double degrees) nogil double radsToDegs(double radians) nogil int getResolution(H3int h) nogil int getBaseCellNumber(H3int h) nogil + H3Error getIndexDigit(H3int h, int res, int *out) nogil + H3Error constructCell(int res, int baseCellNumber, const int *digits, H3int *out) nogil H3Error latLngToCell(const LatLng *g, int res, H3int *out) nogil H3Error cellToLatLng(H3int h, LatLng *) nogil diff --git a/src/h3/_cy/util.pxd b/src/h3/_cy/util.pxd index 4d7d962..b584d3a 100644 --- a/src/h3/_cy/util.pxd +++ b/src/h3/_cy/util.pxd @@ -8,6 +8,7 @@ cpdef H3str int_to_str(H3int x) cdef check_cell(H3int h) cdef check_edge(H3int e) -cdef check_res(int res) cdef check_vertex(H3int v) +cdef check_index(H3int h) +cdef check_res(int res) cdef check_distance(int k) diff --git a/src/h3/_cy/util.pyx b/src/h3/_cy/util.pyx index 7b8a9f2..9b070f9 100644 --- a/src/h3/_cy/util.pyx +++ b/src/h3/_cy/util.pyx @@ -1,4 +1,11 @@ -from .h3lib cimport H3int, H3str, isValidCell, isValidDirectedEdge, isValidVertex +from .h3lib cimport ( + H3int, + H3str, + isValidCell, + isValidDirectedEdge, + isValidVertex, + isValidIndex, +) cimport h3lib @@ -7,7 +14,8 @@ from .error_system import ( H3DomainError, H3DirEdgeInvalidError, H3CellInvalidError, - H3VertexInvalidError + H3VertexInvalidError, + H3IndexInvalidError, ) cdef h3lib.LatLng deg2coord(double lat, double lng) nogil: @@ -78,6 +86,10 @@ cdef check_vertex(H3int v): if isValidVertex(v) == 0: raise H3VertexInvalidError('Integer is not a valid H3 vertex: {}'.format(hex(v))) +cdef check_index(H3int h): + if isValidIndex(h) == 0: + raise H3IndexInvalidError('Integer is not a valid H3 index: {}'.format(hex(h))) + cdef check_res(int res): if (res < 0) or (res > 15): raise H3ResDomainError(res) diff --git a/src/h3/api/basic_int/__init__.py b/src/h3/api/basic_int/__init__.py index 09f7deb..47f1c7e 100644 --- a/src/h3/api/basic_int/__init__.py +++ b/src/h3/api/basic_int/__init__.py @@ -1,5 +1,6 @@ # This file is **symlinked** across the APIs to ensure they are exactly the same. from typing import Literal +from array import array from ... import _cy from ..._h3shape import ( @@ -128,6 +129,20 @@ def average_hexagon_edge_length(res, unit='km'): return _cy.average_hexagon_edge_length(res, unit) +def is_valid_index(h): + """Validates *any* H3 index (cell, vertex, or directed edge). + + Returns + ------- + bool + """ + try: + h = _in_scalar(h) + return _cy.is_valid_index(h) + except (ValueError, TypeError): + return False + + def is_valid_cell(h): """ Validates an H3 cell (hexagon or pentagon). @@ -736,10 +751,124 @@ def get_base_cell_number(h): Returns ------- int + + Examples + -------- + >>> h = construct_cell(57, 2, 1, 4) + >>> h + '83728cfffffffff' + >> get_base_cell_number(h) + 57 """ return _cy.get_base_cell_number(_in_scalar(h)) +def get_index_digit(h, res): + """ + Get the index digit of a cell at the given resolution. + + Parameters + ---------- + h : H3Cell + Cell whose index digit will be returned. + res : int + Resolution (``>= 1``) at which to read the digit. + + Returns + ------- + int + The index digit at the requested resolution. + + Examples + -------- + >>> h = construct_cell(7, 2, 1, 4) + >>> h + '830e8cfffffffff' + >>> get_index_digit(h, 1) + 2 + >>> get_index_digit(h, 2) + 1 + >>> get_index_digit(h, 3) + 4 + """ + return _cy.get_index_digit(_in_scalar(h), res) + + +def construct_cell(base_cell_number, *digits, res=None): + """ + Construct cell from base cell and digits. + + Parameters + ---------- + base_cell_number : int + Base cell *number* (``0`` to ``121``). + *digits : int + Sequence of index digits (``0`` to ``6``). + Length of digits will be the resulting resolution of the output cell. + res : int, optional + Resolution of the constructed cell. If provided, it must equal + ``len(digits)``; otherwise it is inferred from the number of digits. + + Returns + ------- + H3Cell + The constructed cell. + + Examples + -------- + >>> construct_cell(7, 2, 1, 4) # resolution 3 cell + '830e8cfffffffff' + + >>> construct_cell(15, 0, 0, 5, 3) # resolution 4 cell + '841e057ffffffff' + + >>> construct_cell(15, 0, 0, 5, 3, res=4) + '841e057ffffffff' + """ + if (res is not None) and (len(digits) != res): + raise ValueError('Resolution must match number of digits.') + + digits = array('i', digits) + o = _cy.construct_cell(base_cell_number, digits) + return _out_scalar(o) + + +def deconstruct_cell(h): + """ + Deconstruct cell into base cell and digits. + + Parameters + ---------- + h : H3Cell + Cell to deconstruct. + + Returns + ------- + list of int + [base_cell_number, digit1, digit2, ..., digitN] + + Examples + -------- + >>> h = construct_cell(7, 2, 1, 4) # resolution 3 cell + >>> h + '830e8cfffffffff' + >>> deconstruct_cell(h) + (7, 2, 1, 4) + + >>> h = construct_cell(15, 0, 0, 5, 3) # resolution 4 cell + >>> h + '841e057ffffffff' + >>> deconstruct_cell(h) + (15, 0, 0, 5, 3) + >>> construct_cell(*deconstruct_cell(h), 0) == cell_to_center_child(h) + """ + res = get_resolution(h) + bc = get_base_cell_number(h) + digits = [get_index_digit(h, r + 1) for r in range(res)] + + return [bc, *digits] + + def are_neighbor_cells(h1, h2): """ Returns ``True`` if ``h1`` and ``h2`` are neighboring cells. diff --git a/src/h3lib b/src/h3lib index f6d1b0b..70d4c9e 160000 --- a/src/h3lib +++ b/src/h3lib @@ -1 +1 @@ -Subproject commit f6d1b0ba0a0eb076abe655ffdd576a445373a39e +Subproject commit 70d4c9e5007d74d77714afa44d5a2e52606828bf diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index f918019..c461582 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -8,6 +8,10 @@ from h3 import ( H3ResMismatchError, H3CellInvalidError, H3NotNeighborsError, + H3DigitDomainError, + H3BaseCellDomainError, + H3DeletedDigitError, + H3IndexInvalidError, ) @@ -597,3 +601,153 @@ def test_to_local_ij_self(): out = h3.cell_to_local_ij(h, h) assert out == (-858, -2766) + + +def test_is_valid_index(): + assert h3.is_valid_index('8001fffffffffff') + assert not h3.is_valid_index('8a28308280fffff') + assert not h3.is_valid_index(123) + assert not h3.is_valid_index('abcd') + + +def test_is_valid_index_2(): + import h3.api.basic_int as h3 + + h = h3.latlng_to_cell(0,0,9) + assert h3.is_valid_index(h) + assert not h3.is_valid_index(h + 1) + assert not h3.is_valid_directed_edge(h) + assert not h3.is_valid_vertex(h) + + e = h3.origin_to_directed_edges(h)[0] + assert h3.is_valid_index(e) + assert not h3.is_valid_index(e + 1) + assert not h3.is_valid_cell(e) + assert not h3.is_valid_vertex(e) + + v = h3.cell_to_vertex(h, 0) + assert h3.is_valid_index(v) + assert not h3.is_valid_index(v + 1) + assert not h3.is_valid_cell(v) + assert not h3.is_valid_directed_edge(v) + + +def test_get_index_digit(): + assert h3.get_index_digit('822377fffffffff', 1) == 5 + assert h3.get_index_digit('822377fffffffff', 2) == 6 + assert h3.get_index_digit('822377fffffffff', 3) == 7 + assert h3.get_index_digit('822377fffffffff', 15) == 7 + + with pytest.raises(H3ResDomainError): + h3.get_index_digit('822377fffffffff', 16) + + with pytest.raises(H3ResDomainError): + h3.get_index_digit('822377fffffffff', 0) + + with pytest.raises(H3ResDomainError): + h3.get_index_digit('822377fffffffff',-1) + + +def test_get_index_digit_non_cells(): + h = h3.construct_cell(111, 3, 6, 4) + assert h == '83def4fffffffff' + + e = h3.origin_to_directed_edges(h)[0] + assert e == '113def4fffffffff' + assert h3.is_valid_directed_edge(e) + assert h3.get_index_digit(e, 1) == 3 + assert h3.get_index_digit(e, 2) == 6 + assert h3.get_index_digit(e, 3) == 4 + + e = h3.int_to_str(1 + h3.str_to_int(e)) + assert not h3.is_valid_directed_edge(e) + assert not h3.is_valid_index(e) + with pytest.raises(H3IndexInvalidError): + h3.get_index_digit(e, 1) + + v = h3.cell_to_vertexes(h)[0] + assert v == '223de1afffffffff' + assert h3.is_valid_vertex(v) + assert h3.get_index_digit(v, 1) == 0 + assert h3.get_index_digit(v, 2) == 3 + assert h3.get_index_digit(v, 3) == 2 + + v = h3.int_to_str(1 + h3.str_to_int(v)) + assert not h3.is_valid_vertex(v) + assert not h3.is_valid_index(v) + with pytest.raises(H3IndexInvalidError): + h3.get_index_digit(v, 1) + + +def test_construct_cell(): + bc = 17 + assert h3.construct_cell(bc, 5, 6) == '822377fffffffff' + assert h3.construct_cell(bc) == '8023fffffffffff' + + digits = [0] * 15 + assert h3.construct_cell(bc, *digits) == '8f2200000000000' + + with pytest.raises(H3ResDomainError): + digits = [0] * 16 + h3.construct_cell(bc, *digits) + + with pytest.raises(ValueError): + digits = [1,2,3,4] + h3.construct_cell(bc, *digits, res=2) + + with pytest.raises(H3DigitDomainError): + h3.construct_cell(121, 1, 7) # 7 is not a valid digit + + with pytest.raises(H3DigitDomainError): + h3.construct_cell(121, 45) # 45 is not a valid digit + + with pytest.raises(H3DigitDomainError): + h3.construct_cell(121, -1) # -1 is not a valid digit + + with pytest.raises(H3BaseCellDomainError): + h3.construct_cell(122) # one past last base cell number + + with pytest.raises(H3DeletedDigitError): + # 4 is a pentagon base cell. first nonzero digit can't be a 1 + h3.construct_cell(4, 1) + + with pytest.raises(H3DeletedDigitError): + # 4 is a pentagon base cell. first nonzero digit can't be a 1 + h3.construct_cell(4, 0,0,0, 0, 1) + + +def test_deconstruct_cell(): + h = '822377fffffffff' + assert h3.deconstruct_cell(h) == [17, 5, 6] + + +def test_construct_cell_inverses(): + # demonstrate functions are inverses of each other + + h = '8ff3ac688d63446' + components = [121, 6, 5, 4, 3, 2, 1, 0, 6, 5, 4, 3, 2, 1, 0, 6] + + assert h3.construct_cell(*components) == h + assert h3.deconstruct_cell(h) == components + + assert h3.construct_cell(*h3.deconstruct_cell(h)) == h + assert h3.deconstruct_cell(h3.construct_cell(*components)) == components + + +def test_construct_cell_inverses_int_api(): + # same inverse test as above, but in int api + import h3.api.basic_int as h3 + + h = 0x8ff3ac688d63446 + components = [121, 6, 5, 4, 3, 2, 1, 0, 6, 5, 4, 3, 2, 1, 0, 6] + + assert h3.construct_cell(*components) == h + assert h3.deconstruct_cell(h) == components + + assert h3.construct_cell(*h3.deconstruct_cell(h)) == h + assert h3.deconstruct_cell(h3.construct_cell(*components)) == components + + +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) diff --git a/tests/test_lib/test_error_codes.py b/tests/test_lib/test_error_codes.py index 9961178..4ae1d37 100644 --- a/tests/test_lib/test_error_codes.py +++ b/tests/test_lib/test_error_codes.py @@ -1,6 +1,10 @@ import pytest import h3 +from h3._cy import ( + error_code_to_exception, + get_H3_ERROR_END, +) # todo: maybe check the `check_for_error` function behavior directly? @@ -12,24 +16,30 @@ h3_exceptions = { h3.H3GridNavigationError: None, h3.H3MemoryError: None, h3.H3ValueError: None, - - h3.H3FailedError: 1, - h3.H3DomainError: 2, - h3.H3LatLngDomainError: 3, - h3.H3ResDomainError: 4, - h3.H3CellInvalidError: 5, - h3.H3DirEdgeInvalidError: 6, - h3.H3UndirEdgeInvalidError: 7, - h3.H3VertexInvalidError: 8, - h3.H3PentagonError: 9, - h3.H3DuplicateInputError: 10, - h3.H3NotNeighborsError: 11, - h3.H3ResMismatchError: 12, - h3.H3MemoryAllocError: 13, - h3.H3MemoryBoundsError: 14, - h3.H3OptionInvalidError: 15, } +for e in range(1, get_H3_ERROR_END()): + ex = error_code_to_exception(e) + h3_exceptions[ex] = e + + +def test_num_error_codes(): + assert get_H3_ERROR_END() >= 20 + assert error_code_to_exception(19) == h3.H3DeletedDigitError + + # H3_ERROR_END (and beyond) shouldn't be a valid error code + code = get_H3_ERROR_END() + assert isinstance( + error_code_to_exception(code), + h3.UnknownH3ErrorCode + ) + + code = get_H3_ERROR_END() + 1 + assert isinstance( + error_code_to_exception(code), + h3.UnknownH3ErrorCode + ) + def test_error_codes_match(): """ From 73cd306f074a92dd5a0097f7f3347aed4bda198b Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Fri, 12 Dec 2025 13:10:22 -0800 Subject: [PATCH 20/63] Prep for release of v4.4.0 (#471) --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5349789..672478a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ avoid adding features or APIs which do not map onto the ## Unreleased +## [4.4.0] - 2025-12-12 + - Update `h3lib` to v4.4.1. (#470) - Add new error codes: - `H3IndexInvalidError` From 9f52d7445818f819a22351fa013ebd596ffdc32d Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Sun, 14 Dec 2025 14:17:09 -0800 Subject: [PATCH 21/63] attempt to fix docs publishing (#472) --- .github/workflows/build_docs.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index f8301d1..23b884f 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -6,6 +6,9 @@ on: pull_request: branches: ['*'] +permissions: + contents: write + jobs: build-docs: runs-on: ubuntu-22.04 From b70122a20e42e90d0e2c257247010f562d0b6cfa Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Mon, 15 Dec 2025 10:44:10 -0800 Subject: [PATCH 22/63] Update version badge for h3 to v4.4.1 (#473) --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 1a82d89..843324e 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ [![PyPI version](https://badge.fury.io/py/h3.svg)](https://badge.fury.io/py/h3) [![PyPI downloads](https://img.shields.io/pypi/dm/h3.svg)](https://pypistats.org/packages/h3) [![conda](https://img.shields.io/conda/vn/conda-forge/h3-py.svg)](https://anaconda.org/conda-forge/h3-py) -[![version](https://img.shields.io/badge/h3-v4.3.0-blue.svg)](https://github.com/uber/h3/releases/tag/v4.3.0) +[![version](https://img.shields.io/badge/h3-v4.4.1-blue.svg)](https://github.com/uber/h3/releases/tag/v4.4.1) [![version](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/uber/h3-py/blob/master/LICENSE) [![Tests](https://github.com/uber/h3-py/workflows/tests/badge.svg)](https://github.com/uber/h3-py/actions) From 7d6d37945dfbd5ece3cfe7733f2dc4120f43611b Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Mon, 15 Dec 2025 10:56:09 -0800 Subject: [PATCH 23/63] Avoid building duplicate wheels (#474) * avoid building duplicate wheels * add additional CI twine check * add back macos-14 (should fail) * remove macos-14 (should pass) --- .github/workflows/wheels.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index cde27d7..0f685c3 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -60,9 +60,6 @@ jobs: strategy: matrix: include: - - os: macos-14 - build: 'cp*-macosx_arm64' - name: macOS14 - os: macos-15 build: 'cp*-macosx_arm64' name: macOS15 @@ -192,8 +189,22 @@ jobs: retention-days: 7 compression-level: 9 - to_pypi: + check_merged: needs: [merge] + runs-on: ubuntu-latest + steps: + - name: Download merged artifacts + uses: actions/download-artifact@v6.0.0 + with: + name: wheels_and_sdist + path: dist + + - name: Check all wheels and sdist with Twine + run: | + pipx run twine check dist/* + + to_pypi: + needs: [check_merged] if: github.event_name == 'release' && github.event.action == 'published' runs-on: ubuntu-latest From 486f6efd39fe50715715bd450a7f532204d80b97 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Mon, 15 Dec 2025 13:44:12 -0800 Subject: [PATCH 24/63] Prep for v4.4.1 release (#475) --- CHANGELOG.md | 6 +++++- pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 672478a..b6dece2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,11 @@ avoid adding features or APIs which do not map onto the ## Unreleased -## [4.4.0] - 2025-12-12 +## [4.4.1] - 2025-12-15 + +- Fix PyPI publishing issue (#474) + +## [4.4.0] - 2025-12-12 (never published on PyPI) - Update `h3lib` to v4.4.1. (#470) - Add new error codes: diff --git a/pyproject.toml b/pyproject.toml index 4a5e319..bfe0bda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.4.0' +version = '4.4.1' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} From 44dd11fd10da06ae6445ad8f55317cd7382662ad Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 29 Jan 2026 09:35:34 -0800 Subject: [PATCH 25/63] check for error from cellsToLinkedMultiPolygon; add test (#477) --- src/h3/_cy/to_multipoly.pyx | 5 +- tests/test_lib/polyfill/test_to_multipoly.py | 56 +++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/h3/_cy/to_multipoly.pyx b/src/h3/_cy/to_multipoly.pyx index db29baa..d24e2c3 100644 --- a/src/h3/_cy/to_multipoly.pyx +++ b/src/h3/_cy/to_multipoly.pyx @@ -1,6 +1,7 @@ cimport h3lib from h3lib cimport H3int from .util cimport check_cell, coord2deg +from .error_system cimport check_for_error # todo: it's driving me crazy that these three functions are all essentially the same linked list walker... @@ -39,7 +40,9 @@ def _to_multi_polygon(const H3int[:] cells): for h in cells: check_cell(h) - h3lib.cellsToLinkedMultiPolygon(&cells[0], len(cells), &polygon) + check_for_error( + h3lib.cellsToLinkedMultiPolygon(&cells[0], len(cells), &polygon) + ) out = walk_polys(&polygon) diff --git a/tests/test_lib/polyfill/test_to_multipoly.py b/tests/test_lib/polyfill/test_to_multipoly.py index 61f77f6..311c8ca 100644 --- a/tests/test_lib/polyfill/test_to_multipoly.py +++ b/tests/test_lib/polyfill/test_to_multipoly.py @@ -1,5 +1,7 @@ -import h3 +import pytest +import h3 +from h3._cy.error_system import H3FailedError from .. import util as u @@ -47,3 +49,55 @@ def test_2_polys(): cells ) assert set(map(len, out)) == {1, 12} + + +def test_cells_to_h3shape_transmeridian_error(): + """ + Test for https://github.com/uber/h3-py/issues/476 + + Cells along the equator and meridian trigger an error in the C library's + normalizeMultiPolygon. Previously this caused a segfault because the error + code wasn't checked. Now it should raise H3FailedError. + """ + cells = [ + '81007ffffffffff', '81017ffffffffff', '81033ffffffffff', + '81047ffffffffff', '81057ffffffffff', '81093ffffffffff', + '81097ffffffffff', '8109bffffffffff', '810cbffffffffff', + '810dbffffffffff', '81167ffffffffff', '81177ffffffffff', + '81187ffffffffff', '81197ffffffffff', '81227ffffffffff', + '8132bffffffffff', '8133bffffffffff', '81383ffffffffff', + '8138bffffffffff', '81397ffffffffff', '8147bffffffffff', + '8158bffffffffff', '81593ffffffffff', '8159bffffffffff', + '815abffffffffff', '815bbffffffffff', '815f3ffffffffff', + '81617ffffffffff', '81657ffffffffff', '8166fffffffffff', + '8168bffffffffff', '8168fffffffffff', '816abffffffffff', + '816afffffffffff', '816c7ffffffffff', '816cfffffffffff', + '816f3ffffffffff', '816f7ffffffffff', '816fbffffffffff', + '81707ffffffffff', '8170bffffffffff', '8170fffffffffff', + '8171bffffffffff', '8172bffffffffff', '8172fffffffffff', + '8173bffffffffff', '81743ffffffffff', '8174bffffffffff', + '81753ffffffffff', '81757ffffffffff', '81763ffffffffff', + '81767ffffffffff', '8177bffffffffff', '81783ffffffffff', + '81787ffffffffff', '8179bffffffffff', '817a3ffffffffff', + '817a7ffffffffff', '817bbffffffffff', '817c3ffffffffff', + '817c7ffffffffff', '817cbffffffffff', '817e3ffffffffff', + '817ebffffffffff', '817efffffffffff', '817f7ffffffffff', + '817fbffffffffff', '81807ffffffffff', '8180bffffffffff', + '8180fffffffffff', '81827ffffffffff', '8182bffffffffff', + '8182fffffffffff', '81853ffffffffff', '81857ffffffffff', + '8186bffffffffff', '8186fffffffffff', '8188bffffffffff', + '8188fffffffffff', '818a7ffffffffff', '818afffffffffff', + '818cbffffffffff', '818cfffffffffff', '818f3ffffffffff', + '81933ffffffffff', '81987ffffffffff', '81997ffffffffff', + '819a7ffffffffff', '819b7ffffffffff', '81ac7ffffffffff', + '81ba3ffffffffff', '81bafffffffffff', '81bb3ffffffffff', + '81c07ffffffffff', '81c17ffffffffff', '81d0bffffffffff', + '81d1bffffffffff', '81db3ffffffffff', '81dbbffffffffff', + '81dcbffffffffff', '81ddbffffffffff', '81e67ffffffffff', + '81eabffffffffff', '81eafffffffffff', '81ed7ffffffffff', + '81eebffffffffff', '81efbffffffffff', '81f17ffffffffff', + '81f2bffffffffff', '81f33ffffffffff', '81f3bffffffffff', + ] + + with pytest.raises(H3FailedError): + h3.cells_to_h3shape(cells) From 26084144a264b978c1a7a0cfe6e9d261e58d4da3 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 29 Jan 2026 10:20:16 -0800 Subject: [PATCH 26/63] prep for v4.4.2 release (#478) --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6dece2..662c3fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ avoid adding features or APIs which do not map onto the ## Unreleased +## [4.4.2] - 2026-01-29 + +- Check for error from `cellsToLinkedMultiPolygon` (#477) + ## [4.4.1] - 2025-12-15 - Fix PyPI publishing issue (#474) diff --git a/pyproject.toml b/pyproject.toml index bfe0bda..ad6d0a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.4.1' +version = '4.4.2' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} From 3355f53aa6d213fe4c7f38e62765f5b86815932e Mon Sep 17 00:00:00 2001 From: Salman Chishti Date: Wed, 11 Feb 2026 20:51:02 +0000 Subject: [PATCH 27/63] Upgrade GitHub Actions for Node 24 compatibility (#479) Signed-off-by: Salman Muin Kayser Chishti <13schishti@gmail.com> --- .github/workflows/build_docs.yml | 6 +++--- .github/workflows/lint_and_coverage.yml | 4 ++-- .github/workflows/tests.yml | 4 ++-- .github/workflows/wheels.yml | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 23b884f..ae8140e 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -14,11 +14,11 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v5.0.0 + - uses: actions/checkout@v6.0.2 with: submodules: recursive - - uses: actions/setup-python@v6.0.0 + - uses: actions/setup-python@v6.2.0 with: python-version: 3.11 @@ -31,7 +31,7 @@ jobs: run: jupyter-book build docs/ --warningiserror --keep-going --all - name: Upload artifacts - uses: actions/upload-artifact@v5.0.0 + uses: actions/upload-artifact@v6.0.0 with: name: html path: docs/_build/html diff --git a/.github/workflows/lint_and_coverage.yml b/.github/workflows/lint_and_coverage.yml index d9789c7..b10b1de 100644 --- a/.github/workflows/lint_and_coverage.yml +++ b/.github/workflows/lint_and_coverage.yml @@ -12,11 +12,11 @@ jobs: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v5.0.0 + - uses: actions/checkout@v6.0.2 with: submodules: recursive - - uses: actions/setup-python@v6.0.0 + - uses: actions/setup-python@v6.2.0 with: python-version: 3.11 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a82ec98..8b79555 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,11 +17,11 @@ jobs: python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] steps: - - uses: actions/checkout@v5.0.0 + - uses: actions/checkout@v6.0.2 with: submodules: recursive - - uses: actions/setup-python@v6.0.0 + - uses: actions/setup-python@v6.2.0 with: python-version: '${{ matrix.python-version }}' diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 0f685c3..7e7caed 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -23,12 +23,12 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v5.0.0 + - uses: actions/checkout@v6.0.2 with: submodules: recursive - name: Setup Python - uses: actions/setup-python@v6.0.0 + uses: actions/setup-python@v6.2.0 with: python-version: 3.11 @@ -48,7 +48,7 @@ jobs: run: pytest - name: Upload artifacts to GitHub - uses: actions/upload-artifact@v5.0.0 + uses: actions/upload-artifact@v6.0.0 with: name: temp_result_sdist path: ./dist @@ -130,7 +130,7 @@ jobs: name: Linux Aarch64 3.14 steps: - - uses: actions/checkout@v5.0.0 + - uses: actions/checkout@v6.0.2 with: submodules: recursive @@ -171,7 +171,7 @@ jobs: pipx run twine check wheelhouse/* - name: Upload artifacts to GitHub - uses: actions/upload-artifact@v5.0.0 + uses: actions/upload-artifact@v6.0.0 with: name: temp_result_${{ matrix.os }}-${{ strategy.job-index }} path: wheelhouse/*.whl @@ -194,7 +194,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Download merged artifacts - uses: actions/download-artifact@v6.0.0 + uses: actions/download-artifact@v7.0.0 with: name: wheels_and_sdist path: dist @@ -209,7 +209,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v6.0.0 + - uses: actions/download-artifact@v7.0.0 with: name: wheels_and_sdist path: dist From 4d0c33241bddd5415769d693c987a33f68b9af3b Mon Sep 17 00:00:00 2001 From: Salman Chishti Date: Sun, 15 Feb 2026 21:25:25 +0000 Subject: [PATCH 28/63] Upgrade GitHub Actions to latest versions (#480) Signed-off-by: Salman Muin Kayser Chishti <13schishti@gmail.com> --- .github/workflows/wheels.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 7e7caed..9f40ef7 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -155,11 +155,11 @@ jobs: - name: Set up QEMU if: runner.os == 'Linux' - uses: docker/setup-qemu-action@v3.6.0 + uses: docker/setup-qemu-action@v3.7.0 with: platforms: aarch64 - - uses: pypa/cibuildwheel@v3.2.1 + - uses: pypa/cibuildwheel@v3.3.1 env: CIBW_TEST_REQUIRES: pytest pytest-cov numpy CIBW_TEST_COMMAND: pytest {project}/tests @@ -181,7 +181,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Merge Artifacts - uses: actions/upload-artifact/merge@v5.0.0 + uses: actions/upload-artifact/merge@v6 with: name: wheels_and_sdist pattern: temp_result_* From 9a7d6dfd6f2813e1d448151dbb7e25def752f018 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 26 Feb 2026 14:12:54 -0800 Subject: [PATCH 29/63] v4.5a (alpha version) (#483) * bump h3lib to unreleased a9c0a2e (cellsToMultiPolygon) * initial changes * move around dependencies * update CI * ci separation * h3.pc.in * clean up .gitignore * changelog * better changelog * add cellsToMultiPolygon to h3-py in separate release * sdist exclude and coverage for version test * warn that changing some justfile rules will affect CI * try to silence some CI warnings * one more warning --- .github/workflows/build_docs.yml | 11 ++-- .github/workflows/lint_and_coverage.yml | 24 ++++--- .github/workflows/tests.yml | 20 +++--- .github/workflows/wheels.yml | 48 ++++++-------- .gitignore | 86 ++++++++++--------------- CHANGELOG.md | 7 ++ dev_notes.md | 15 ++++- justfile | 61 ++++++++++++++++++ makefile | 52 --------------- pyproject.toml | 24 ++++--- src/h3lib | 2 +- tests/test_lib/test_cells_and_edges.py | 8 ++- 12 files changed, 183 insertions(+), 175 deletions(-) create mode 100644 justfile delete mode 100644 makefile diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index ae8140e..9cc00a2 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -18,17 +18,14 @@ jobs: with: submodules: recursive - - uses: actions/setup-python@v6.2.0 + - uses: astral-sh/setup-uv@v7 with: - python-version: 3.11 + python-version: '3.11' - - name: Install dependencies - run: | - pip install --upgrade pip setuptools wheel - pip install .[all] + - uses: extractions/setup-just@v2 - name: Build the book - run: jupyter-book build docs/ --warningiserror --keep-going --all + run: just docs - name: Upload artifacts uses: actions/upload-artifact@v6.0.0 diff --git a/.github/workflows/lint_and_coverage.yml b/.github/workflows/lint_and_coverage.yml index b10b1de..c0eb154 100644 --- a/.github/workflows/lint_and_coverage.yml +++ b/.github/workflows/lint_and_coverage.yml @@ -16,22 +16,20 @@ jobs: with: submodules: recursive - - uses: actions/setup-python@v6.2.0 + - uses: astral-sh/setup-uv@v7 with: - python-version: 3.11 + python-version: '3.11' - - name: Install from source - run: pip install .[test] + - uses: extractions/setup-just@v2 - - name: Run Linting - uses: astral-sh/ruff-action@v3 + - name: Lint + run: just lint - - name: Coverage Requirement - Library - run: | - pytest tests/test_lib --cov=h3 --cov=tests/test_lib --cov-fail-under=100 + - name: Install + run: uv sync + + - name: Coverage - Library + run: just ci-test - name: Coverage - Cython - run: | - pip install cython - cythonize tests/test_cython/cython_example.pyx - pytest tests/test_cython --cov=tests/test_cython + run: just ci-test-cython diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8b79555..7920a84 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,17 +14,19 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-22.04] - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] + python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] steps: - uses: actions/checkout@v6.0.2 with: submodules: recursive - - uses: actions/setup-python@v6.2.0 + - uses: astral-sh/setup-uv@v7 with: python-version: '${{ matrix.python-version }}' + - uses: extractions/setup-just@v2 + ## Start Windows stuff - uses: ilammy/msvc-dev-cmd@v1.13.0 if: startsWith(matrix.os, 'windows') @@ -36,13 +38,11 @@ jobs: echo "CXX=cl.exe" >> $GITHUB_ENV ## End Windows stuff - - name: Install from source - run: | - pip install --upgrade pip setuptools wheel - pip install .[test] + - name: Install + run: uv sync - name: Tests - run: | - pip install cython - cythonize tests/test_cython/cython_example.pyx - pytest + run: just ci-test + + - name: Cython Tests + run: just ci-test-cython diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 9f40ef7..dbc8d6d 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -27,25 +27,25 @@ jobs: with: submodules: recursive - - name: Setup Python - uses: actions/setup-python@v6.2.0 + - uses: astral-sh/setup-uv@v7 with: - python-version: 3.11 + python-version: '3.11' + - name: Make sdist - run: | - python --version - pipx --version - pipx run build --sdist + run: uv build --sdist + # Test the sdist, NOT the local checkout. + # Use a fresh venv + uv pip install (not uv sync, which would build from source). - name: Install from sdist run: | - pip install --upgrade pip setuptools wheel + uv venv cp dist/h3-*.tar.gz h3.tar.gz - pip install h3.tar.gz[test] + uv pip install h3.tar.gz[numpy] pytest pytest-cov - name: Test sdist - run: pytest + # run pytest directly from the venv to avoid `uv run` syncing from the local checkout + run: .venv/bin/pytest - name: Upload artifacts to GitHub uses: actions/upload-artifact@v6.0.0 @@ -85,12 +85,6 @@ jobs: build: 'cp*-manylinux_x86_64' name: Linux Intel glibc 64-bit - - os: ubuntu-22.04 - build: 'cp38-musllinux_x86_64' - name: Linux Intel musl 64-bit 3.8 - - os: ubuntu-22.04 - build: 'cp39-musllinux_x86_64' - name: Linux Intel musl 64-bit 3.9 - os: ubuntu-22.04 build: 'cp310-musllinux_x86_64' name: Linux Intel musl 64-bit 3.10 @@ -107,12 +101,6 @@ jobs: build: 'cp314-musllinux_x86_64' name: Linux Intel musl 64-bit 3.14 - - os: ubuntu-22.04 - build: 'cp38-manylinux_aarch64' - name: Linux Aarch64 3.8 - - os: ubuntu-22.04 - build: 'cp39-manylinux_aarch64' - name: Linux Aarch64 3.9 - os: ubuntu-22.04 build: 'cp310-manylinux_aarch64' name: Linux Aarch64 3.10 @@ -134,7 +122,9 @@ jobs: with: submodules: recursive - - name: Set MSVC for Windows-x64 + - uses: astral-sh/setup-uv@v7 + + - name: Set MSVC for Windows-x64 uses: microsoft/setup-msbuild@v2 if: matrix.os == 'windows-latest' with: @@ -161,14 +151,14 @@ jobs: - uses: pypa/cibuildwheel@v3.3.1 env: + CIBW_BUILD_FRONTEND: 'build[uv]' CIBW_TEST_REQUIRES: pytest pytest-cov numpy CIBW_TEST_COMMAND: pytest {project}/tests CIBW_ARCHS_LINUX: auto aarch64 CIBW_BUILD: ${{ matrix.build }} - name: Check with Twine - run: | - pipx run twine check wheelhouse/* + run: uvx twine check wheelhouse/* - name: Upload artifacts to GitHub uses: actions/upload-artifact@v6.0.0 @@ -193,6 +183,11 @@ jobs: needs: [merge] runs-on: ubuntu-latest steps: + - uses: astral-sh/setup-uv@v7 + with: + enable-cache: false + ignore-empty-workdir: true + - name: Download merged artifacts uses: actions/download-artifact@v7.0.0 with: @@ -200,8 +195,7 @@ jobs: path: dist - name: Check all wheels and sdist with Twine - run: | - pipx run twine check dist/* + run: uvx twine check dist/* to_pypi: needs: [check_merged] diff --git a/.gitignore b/.gitignore index cf6fcf3..1141de9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,75 +1,57 @@ -h3c/ +# Byte-compiled / optimized *.py[cod] -.cache/ -h3/out/ -.ruff_cache/ -_build/ +__pycache__/ + +# C extensions +*.so # Generated C code from Cython test tests/**/*.c # Cython HTML annotations *.html -# C extensions -*.so - -# Packages -*.egg +# Build artifacts +build/ +dist/ *.egg-info -dist -build -eggs -parts -bin -var -sdist -develop-eggs -.installed.cfg -# Installer logs -pip-log.txt - -# Unit test / coverage reports +# Coverage .coverage coverage.xml coverage.lcov -.tox -nosetests.xml -.noseids -.pytest_cache - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -*.csv -build/ -env/ -env_docs/ -docs/_build/ htmlcov/ -# vim/emacs backup files +# Test +.pytest_cache/ + +# Tools +.ruff_cache/ +.cache/ + +# Docs +_build/ +docs/_build/ + +# Environment +.venv/ +uv.lock + +# OS +.DS_Store + +# Editor backup files *~ \#*\# .\#* .*.sw* -#DB snapshots -db_snapshots/ - -#OSX -.DS_Store - -node_modules/ -bower_components/ -.sass-cache/ +# IDE .idea/ -.unison.* +# IPython / Jupyter .ipynb_checkpoints/ -_skbuild/ -# might want to remove this later when distributing -MANIFEST +# Legacy build dirs +_skbuild/ +h3c/ +h3/out/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 662c3fc..b71f774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,13 @@ avoid adding features or APIs which do not map onto the ## Unreleased +## [4.5.0a1] - 2026-02-25 + +- Update `h3lib` with draft v4.5 changes +- Drop Python 3.8 and 3.9 (EOL); minimum is now Python 3.10 +- Document Python 3.14 support +- Migrate build tooling from Makefile/pip to justfile/uv, including CI + ## [4.4.2] - 2026-01-29 - Check for error from `cellsToLinkedMultiPolygon` (#477) diff --git a/dev_notes.md b/dev_notes.md index 300ee42..d8635b0 100644 --- a/dev_notes.md +++ b/dev_notes.md @@ -2,11 +2,20 @@ ## Install for development +This repo uses [`just`](https://github.com/casey/just) for running common development commands. + +To get started: + - `git clone git@github.com:uber/h3-py.git` - `cd h3-py` -- `make init` -- `make test` -- `make lint` +- `just lint` +- `just test` +- `just test-cython` + +To build and view docs: + +- `just docs` +- `just view` ## Docstrings diff --git a/justfile b/justfile new file mode 100644 index 0000000..d8e44fb --- /dev/null +++ b/justfile @@ -0,0 +1,61 @@ +# disable editable installs so uv sync does a full build of the C extension +export UV_NO_EDITABLE := "1" + +_: + just --list + +# force-rebuild the C extension to avoid stale builds +reinstall: + uv cache clean h3 + uv sync --reinstall-package h3 + +# locally, always reinstall before testing +test: reinstall ci-test +test-cython: reinstall ci-test-cython + +fix: + uvx ruff check --fix + +lab: + uv sync --group docs + uv run jupyter lab + +view: + open docs/_build/html/index.html + +purge: + just _rm .venv + just _rm '*.pytest_cache' + just _rm .DS_Store + just _rm '*.egg-info' + just _rm dist + just _rm '*.ipynb_checkpoints' + just _rm __pycache__ + just _rm uv.lock + just _rm .coverage + just _rm build + just _rm _build + just _rm _skbuild + just _rm .ruff_cache + uv cache clean h3 + +_rm pattern: + -@find . -name "{{pattern}}" -prune -exec rm -rf {} + + + +# Recipes below are used by CI workflows (.github/workflows/). +# Changes here may break CI — update the workflows accordingly. + +ci-test: + uv run pytest tests/test_lib --cov=h3 --cov=tests/test_lib --cov-fail-under=100 + +ci-test-cython: + uv run --with cython --with setuptools cythonize tests/test_cython/cython_example.pyx + uv run pytest tests/test_cython --cov=tests/test_cython + +lint: + uvx ruff check + +docs: + uv sync --group docs + uv run jupyter-book build docs/ --warningiserror --keep-going --all diff --git a/makefile b/makefile deleted file mode 100644 index df39c8f..0000000 --- a/makefile +++ /dev/null @@ -1,52 +0,0 @@ -.PHONY: init clear rebuild purge test lint lab ipython - -PYTHON=$(shell command -v python || command -v python3) - - -build-docs: - ./env/bin/pip install .[all] - ./env/bin/jupyter-book build docs/ --warningiserror --keep-going --all - -open: - open docs/_build/html/index.html - -init: purge - git submodule update --init - $(PYTHON) -m venv env - ./env/bin/pip install --upgrade pip wheel setuptools - ./env/bin/pip install .[test] - -clear: - -./env/bin/pip uninstall -y h3 - -@rm -rf MANIFEST - -@rm -rf .pytest_cache _skbuild dist .coverage build docs/_build .ruff_cache - -@find . -type d -name '__pycache__' | xargs rm -r - -@find . -type d -name '*.egg-info' | xargs rm -r - -@find . -type f -name '*.pyc' | xargs rm -r - -@find . -type f -name '*.so' | xargs rm -r - -@find . -type d -name '*.ipynb_checkpoints' | xargs rm -r - -@find ./tests -type f -name '*.c' | xargs rm -r - -@find ./tests -type f -name '*.html' | xargs rm -r - -rebuild: clear - ./env/bin/pip install .[test] - -purge: clear - -@rm -rf env - -test: - ./env/bin/pytest tests/test_lib --cov=h3 --cov=tests/test_lib --cov-fail-under=100 - - ./env/bin/pip install cython - ./env/bin/cythonize tests/test_cython/cython_example.pyx - ./env/bin/pytest tests/test_cython --cov=tests/test_cython - -lint: - ./env/bin/ruff check - -fix: - ./env/bin/ruff check --fix - -lab: - ./env/bin/pip install .[all] - ./env/bin/jupyter lab diff --git a/pyproject.toml b/pyproject.toml index ad6d0a0..3c9effe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.4.2' +version = '4.5.0a1' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} @@ -14,7 +14,7 @@ authors = [ maintainers = [ { name = 'AJ Friend', email = 'ajfriend@gmail.com' }, ] -requires-python = '>=3.8' +requires-python = '>=3.10' dependencies = [] @@ -25,12 +25,11 @@ classifiers = [ 'License :: OSI Approved :: Apache Software License', 'Programming Language :: C', 'Programming Language :: Cython', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: 3.13', + 'Programming Language :: Python :: 3.14', 'Operating System :: MacOS :: MacOS X', 'Operating System :: POSIX :: Linux', 'Operating System :: Microsoft :: Windows', @@ -47,9 +46,11 @@ Changelog = 'https://uber.github.io/h3-py/_changelog.html' [project.optional-dependencies] numpy = ['numpy'] -test = ['pytest', 'pytest-cov', 'ruff', 'numpy'] -all = [ - 'h3[test]', + +[dependency-groups] +dev = ['pytest', 'pytest-cov', 'numpy'] +docs = [ + 'numpy', 'jupyter-book<2', 'sphinx>=7.3.3', # https://github.com/sphinx-doc/sphinx/issues/12290 'jupyterlab', @@ -73,18 +74,25 @@ omit = [ ] +[tool.uv] +default-groups = ['dev'] + [tool.scikit-build] sdist.exclude = [ 'src/h3lib', 'docs', 'dev_notes.md', - 'makefile', + 'justfile', + '.github', + '.gitignore', + '.gitmodules', ] sdist.include = [ 'src/h3lib/LICENSE', 'src/h3lib/README.md', 'src/h3lib/VERSION', 'src/h3lib/CMakeLists.txt', + 'src/h3lib/h3.pc.in', 'src/h3lib/cmake/*', 'src/h3lib/src/h3lib/*' ] diff --git a/src/h3lib b/src/h3lib index 70d4c9e..a9c0a2e 160000 --- a/src/h3lib +++ b/src/h3lib @@ -1 +1 @@ -Subproject commit 70d4c9e5007d74d77714afa44d5a2e52606828bf +Subproject commit a9c0a2ec7869fa01772dcebdf930590469910600 diff --git a/tests/test_lib/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py index c461582..4b8e107 100644 --- a/tests/test_lib/test_cells_and_edges.py +++ b/tests/test_lib/test_cells_and_edges.py @@ -456,8 +456,12 @@ def test_versions(): v_c = Version(v['c']) v_p = Version(v['python']) - # of X.Y.Z, X and Y must match - assert v_c.release[:2] == v_p.release[:2] + # For all releases (including pre-release), major version must match + assert v_c.release[0] == v_p.release[0] + + if not v_p.is_prerelease: # pragma: no cover + # of X.Y.Z, X and Y must match + assert v_c.release[:2] == v_p.release[:2] def test_str_int_convert(): From adba976e22a65a5b1ae29eabe8782ff5922f843b Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Fri, 27 Feb 2026 19:28:16 -0800 Subject: [PATCH 30/63] v4.5.0a2 (#484) * first pass * helper * better tests * changelog * better comments * be robust against os-specific floating point behavior --- CHANGELOG.md | 8 + pyproject.toml | 2 +- src/h3/_cy/h3lib.pxd | 25 +- src/h3/_cy/to_multipoly.pyx | 70 ++-- tests/test_lib/polyfill/test_to_multipoly.py | 349 ++++++++++++++++--- 5 files changed, 343 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b71f774..64fe3e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,14 @@ avoid adding features or APIs which do not map onto the ## Unreleased +## [4.5.0a2] - 2026-02-27 + +- `cells_to_h3shape`/`cells_to_geo` now handle all valid cell sets, including + sets that would produce global polygons crossing the antimeridian, poles, or are larger than a hemisphere + - Duplicate cells now raise `H3DuplicateInputError` + - Mixed-resolution cells now raise `H3ResMismatchError` + - Internal: switch from linked-list to array-based C API for cells-to-polygon conversion + ## [4.5.0a1] - 2026-02-25 - Update `h3lib` with draft v4.5 changes diff --git a/pyproject.toml b/pyproject.toml index 3c9effe..1da4918 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.5.0a1' +version = '4.5.0a2' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} diff --git a/src/h3/_cy/h3lib.pxd b/src/h3/_cy/h3lib.pxd index 8cf74a7..7dfa0c5 100644 --- a/src/h3/_cy/h3lib.pxd +++ b/src/h3/_cy/h3lib.pxd @@ -47,21 +47,6 @@ cdef extern from 'h3api.h': int i int j - ctypedef struct LinkedLatLng: - LatLng data 'vertex' - LinkedLatLng *next - - # renaming these for clarity - ctypedef struct LinkedGeoLoop: - LinkedLatLng *data 'first' - LinkedLatLng *_data_last 'last' # not needed in Cython bindings - LinkedGeoLoop *next - - ctypedef struct LinkedGeoPolygon: - LinkedGeoLoop *data 'first' - LinkedGeoLoop *_data_last 'last' # not needed in Cython bindings - LinkedGeoPolygon *next - ctypedef struct GeoLoop: int numVerts LatLng *verts @@ -171,8 +156,8 @@ cdef extern from 'h3api.h': double greatCircleDistanceKm(const LatLng *a, const LatLng *b) nogil double greatCircleDistanceM(const LatLng *a, const LatLng *b) nogil - H3Error cellsToLinkedMultiPolygon(const H3int *h3Set, const int numCells, LinkedGeoPolygon *out) - void destroyLinkedMultiPolygon(LinkedGeoPolygon *polygon) + H3Error cellsToMultiPolygon(const H3int *cells, const int64_t numCells, GeoMultiPolygon *out) + void destroyGeoMultiPolygon(GeoMultiPolygon *mpoly) H3Error maxPolygonToCellsSize(const GeoPolygon *geoPolygon, int res, uint32_t flags, uint64_t *count) H3Error polygonToCells(const GeoPolygon *geoPolygon, int res, uint32_t flags, H3int *out) @@ -180,9 +165,9 @@ cdef extern from 'h3api.h': H3Error maxPolygonToCellsSizeExperimental(const GeoPolygon *geoPolygon, int res, uint32_t flags, uint64_t *count) H3Error polygonToCellsExperimental(const GeoPolygon *geoPolygon, int res, uint32_t flags, uint64_t sz, H3int *out) - # ctypedef struct GeoMultiPolygon: - # int numPolygons - # GeoPolygon *polygons + ctypedef struct GeoMultiPolygon: + int numPolygons + GeoPolygon *polygons # int hexRange(H3int origin, int k, H3int *out) diff --git a/src/h3/_cy/to_multipoly.pyx b/src/h3/_cy/to_multipoly.pyx index d24e2c3..ed3e763 100644 --- a/src/h3/_cy/to_multipoly.pyx +++ b/src/h3/_cy/to_multipoly.pyx @@ -4,60 +4,42 @@ from .util cimport check_cell, coord2deg from .error_system cimport check_for_error -# todo: it's driving me crazy that these three functions are all essentially the same linked list walker... -# grumble: no way to do iterators in with cdef functions! -cdef walk_polys(const h3lib.LinkedGeoPolygon* L): - out = [] - while L: - out += [walk_loops(L.data)] - L = L.next - - return out +cdef _loop_to_list(const h3lib.GeoLoop *loop): + return [coord2deg(loop.verts[v]) for v in range(loop.numVerts)] -cdef walk_loops(const h3lib.LinkedGeoLoop* L): - out = [] - while L: - out += [walk_coords(L.data)] - L = L.next - - return out - - -cdef walk_coords(const h3lib.LinkedLatLng* L): - out = [] - while L: - out += [coord2deg(L.data)] - L = L.next - - return out - -# todo: tuples instead of lists? -def _to_multi_polygon(const H3int[:] cells): - cdef: - h3lib.LinkedGeoPolygon polygon - - for h in cells: - check_cell(h) - - check_for_error( - h3lib.cellsToLinkedMultiPolygon(&cells[0], len(cells), &polygon) +cdef _poly_to_lists(const h3lib.GeoPolygon *poly): + return ( + [_loop_to_list(&poly.geoloop)] + + [_loop_to_list(&poly.holes[h]) for h in range(poly.numHoles)] ) - out = walk_polys(&polygon) - # we're still responsible for cleaning up the passed in `polygon`, - # but not a problem here, since it is stack allocated - h3lib.destroyLinkedMultiPolygon(&polygon) +def _to_multi_polygon(const H3int[:] cells): + cdef: + h3lib.GeoMultiPolygon mpoly + H3int cell + + for cell in cells: + check_cell(cell) + + check_for_error( + h3lib.cellsToMultiPolygon(&cells[0], len(cells), &mpoly) + ) + + try: + out = [ + _poly_to_lists(&mpoly.polygons[p]) + for p in range(mpoly.numPolygons) + ] + finally: + h3lib.destroyGeoMultiPolygon(&mpoly) return out def cells_to_multi_polygon(const H3int[:] cells): - # todo: gotta be a more elegant way to handle these... if len(cells) == 0: return [] - multipoly = _to_multi_polygon(cells) - - return multipoly + return _to_multi_polygon(cells) diff --git a/tests/test_lib/polyfill/test_to_multipoly.py b/tests/test_lib/polyfill/test_to_multipoly.py index 311c8ca..80c5a75 100644 --- a/tests/test_lib/polyfill/test_to_multipoly.py +++ b/tests/test_lib/polyfill/test_to_multipoly.py @@ -1,11 +1,21 @@ import pytest import h3 -from h3._cy.error_system import H3FailedError +from h3._cy.error_system import H3DuplicateInputError, H3ResMismatchError, H3FailedError from .. import util as u +def assert_cells_roundtrip(cells): + """Convert cells to multi-polygon and back, checking we recover the original set.""" + res = h3.get_resolution(cells[0]) + mpoly = h3.cells_to_h3shape(cells, tight=False) + + recovered = h3.h3shape_to_cells(mpoly, res) + + assert u.same_set(recovered, cells) + + def test_cells_to_h3shape(): h = '8928308280fffff' cells = h3.grid_disk(h, 1) @@ -51,53 +61,300 @@ def test_2_polys(): assert set(map(len, out)) == {1, 12} -def test_cells_to_h3shape_transmeridian_error(): - """ - Test for https://github.com/uber/h3-py/issues/476 +def test_empty(): + mpoly = h3.cells_to_h3shape([], tight=False) + assert isinstance(mpoly, h3.LatLngMultiPoly) + assert len(mpoly) == 0 - Cells along the equator and meridian trigger an error in the C library's - normalizeMultiPolygon. Previously this caused a segfault because the error - code wasn't checked. Now it should raise H3FailedError. - """ + mpoly = h3.cells_to_h3shape([], tight=True) + assert isinstance(mpoly, h3.LatLngMultiPoly) + assert len(mpoly) == 0 + + +def test_all_res0_cells(): + cells = h3.get_res0_cells() + mpoly = h3.cells_to_h3shape(cells, tight=False) + + # We should get an "entire globe" multipolygon back + # The current implementation returns 8 triangles + assert len(mpoly) == 8 + for poly in mpoly: + assert len(poly.outer) == 3 + assert len(poly.holes) == 0 + + # Roundtrip fails: h3shape_to_cells recovers only 69/122 cells. + # TODO: assert_cells_roundtrip when h3shape_to_cells handles global polygons. + cells2 = h3.h3shape_to_cells(mpoly, 0) + assert len(cells2) == 69 + + +def test_pentagons(): + for res in range(16): + cells = h3.get_pentagons(res) + mpoly = h3.cells_to_h3shape(cells, tight=False) + + if res % 2 == 0: + expected_verts = 5 + else: + # pentagons have distortion vertices at odd resolutions + expected_verts = 10 + + assert len(mpoly) == 12 + for poly in mpoly: + assert len(poly.holes) == 0 + assert len(poly.outer) == expected_verts + + assert_cells_roundtrip(cells) + + +def test_duplicate_cells_error(): + cell = '8928308280fffff' + with pytest.raises(H3DuplicateInputError): + h3.cells_to_h3shape([cell, cell]) + + +def test_mixed_resolution_error(): + with pytest.raises(H3ResMismatchError): + h3.cells_to_h3shape(['8027fffffffffff', '81efbffffffffff']) + + +def test_three_polygons(): cells = [ - '81007ffffffffff', '81017ffffffffff', '81033ffffffffff', - '81047ffffffffff', '81057ffffffffff', '81093ffffffffff', - '81097ffffffffff', '8109bffffffffff', '810cbffffffffff', - '810dbffffffffff', '81167ffffffffff', '81177ffffffffff', - '81187ffffffffff', '81197ffffffffff', '81227ffffffffff', - '8132bffffffffff', '8133bffffffffff', '81383ffffffffff', - '8138bffffffffff', '81397ffffffffff', '8147bffffffffff', - '8158bffffffffff', '81593ffffffffff', '8159bffffffffff', - '815abffffffffff', '815bbffffffffff', '815f3ffffffffff', - '81617ffffffffff', '81657ffffffffff', '8166fffffffffff', - '8168bffffffffff', '8168fffffffffff', '816abffffffffff', - '816afffffffffff', '816c7ffffffffff', '816cfffffffffff', - '816f3ffffffffff', '816f7ffffffffff', '816fbffffffffff', - '81707ffffffffff', '8170bffffffffff', '8170fffffffffff', - '8171bffffffffff', '8172bffffffffff', '8172fffffffffff', - '8173bffffffffff', '81743ffffffffff', '8174bffffffffff', - '81753ffffffffff', '81757ffffffffff', '81763ffffffffff', - '81767ffffffffff', '8177bffffffffff', '81783ffffffffff', - '81787ffffffffff', '8179bffffffffff', '817a3ffffffffff', - '817a7ffffffffff', '817bbffffffffff', '817c3ffffffffff', - '817c7ffffffffff', '817cbffffffffff', '817e3ffffffffff', - '817ebffffffffff', '817efffffffffff', '817f7ffffffffff', - '817fbffffffffff', '81807ffffffffff', '8180bffffffffff', - '8180fffffffffff', '81827ffffffffff', '8182bffffffffff', - '8182fffffffffff', '81853ffffffffff', '81857ffffffffff', - '8186bffffffffff', '8186fffffffffff', '8188bffffffffff', - '8188fffffffffff', '818a7ffffffffff', '818afffffffffff', - '818cbffffffffff', '818cfffffffffff', '818f3ffffffffff', - '81933ffffffffff', '81987ffffffffff', '81997ffffffffff', - '819a7ffffffffff', '819b7ffffffffff', '81ac7ffffffffff', - '81ba3ffffffffff', '81bafffffffffff', '81bb3ffffffffff', - '81c07ffffffffff', '81c17ffffffffff', '81d0bffffffffff', - '81d1bffffffffff', '81db3ffffffffff', '81dbbffffffffff', - '81dcbffffffffff', '81ddbffffffffff', '81e67ffffffffff', - '81eabffffffffff', '81eafffffffffff', '81ed7ffffffffff', - '81eebffffffffff', '81efbffffffffff', '81f17ffffffffff', - '81f2bffffffffff', '81f33ffffffffff', '81f3bffffffffff', + '8027fffffffffff', '802bfffffffffff', '804dfffffffffff', + '8067fffffffffff', '806dfffffffffff', '8049fffffffffff', + '805ffffffffffff', '8057fffffffffff', '807dfffffffffff', + '80a5fffffffffff', '80a9fffffffffff', '808bfffffffffff', + '801bfffffffffff', '8035fffffffffff', '803ffffffffffff', + '8053fffffffffff', '8043fffffffffff', '8021fffffffffff', + '8011fffffffffff', '801ffffffffffff', '8097fffffffffff', ] + mpoly = h3.cells_to_h3shape(cells, tight=False) + + assert len(mpoly) == 3 + hole_counts = [len(p.holes) for p in mpoly] + + # Polygons are ordered by size, and we know the hole counts of each + assert hole_counts == [3, 1, 0] + + assert_cells_roundtrip(cells) + + +def test_issue_1049(): + cells = [ + '827487fffffffff', '82748ffffffffff', '827497fffffffff', + '82749ffffffffff', '8274affffffffff', '8274c7fffffffff', + '8274cffffffffff', '8274d7fffffffff', '8274e7fffffffff', + '8274effffffffff', '8274f7fffffffff', '82754ffffffffff', + '827c07fffffffff', '827c27fffffffff', '827c2ffffffffff', + '827c37fffffffff', '827d87fffffffff', '827d8ffffffffff', + '827d97fffffffff', '827d9ffffffffff', '827da7fffffffff', + '827daffffffffff', '82801ffffffffff', '8280a7fffffffff', + '8280affffffffff', '8280b7fffffffff', '828197fffffffff', + '82819ffffffffff', '8281a7fffffffff', '8281b7fffffffff', + '828207fffffffff', '82820ffffffffff', '828227fffffffff', + '82822ffffffffff', '8282e7fffffffff', '828307fffffffff', + '82830ffffffffff', '82831ffffffffff', '82832ffffffffff', + '828347fffffffff', '82834ffffffffff', '828357fffffffff', + '82835ffffffffff', '828367fffffffff', '828377fffffffff', + '82a447fffffffff', '82a457fffffffff', '82a45ffffffffff', + '82a467fffffffff', '82a46ffffffffff', '82a477fffffffff', + '82a4c7fffffffff', '82a4cffffffffff', '82a4d7fffffffff', + '82a4e7fffffffff', '82a4effffffffff', '82a4f7fffffffff', + '82a547fffffffff', '82a54ffffffffff', '82a557fffffffff', + '82a55ffffffffff', '82a567fffffffff', '82a577fffffffff', + '82a837fffffffff', '82a897fffffffff', '82a8a7fffffffff', + '82a8b7fffffffff', '82a917fffffffff', '82a927fffffffff', + '82a937fffffffff', '82a987fffffffff', '82a98ffffffffff', + '82a997fffffffff', '82a99ffffffffff', '82a9a7fffffffff', + '82a9affffffffff', '82ac47fffffffff', '82ac57fffffffff', + '82ac5ffffffffff', '82ac67fffffffff', '82ac6ffffffffff', + '82ac77fffffffff', '82ad47fffffffff', '82ad4ffffffffff', + '82ad57fffffffff', '82ad5ffffffffff', '82ad67fffffffff', + '82ad77fffffffff', '82c207fffffffff', '82c217fffffffff', + '82c227fffffffff', '82c237fffffffff', '82c287fffffffff', + '82c28ffffffffff', '82c29ffffffffff', '82c2a7fffffffff', + '82c2affffffffff', '82c2b7fffffffff', '82c307fffffffff', + '82c317fffffffff', '82c31ffffffffff', '82c337fffffffff', + '82cfb7fffffffff', '82d0c7fffffffff', '82d0d7fffffffff', + '82d0dffffffffff', '82d0e7fffffffff', '82d0f7fffffffff', + '82d147fffffffff', '82d157fffffffff', '82d15ffffffffff', + '82d167fffffffff', '82d177fffffffff', '82d187fffffffff', + '82d18ffffffffff', '82d197fffffffff', '82d19ffffffffff', + '82d1a7fffffffff', '82d1affffffffff', '82dc47fffffffff', + '82dc57fffffffff', '82dc5ffffffffff', '82dc67fffffffff', + '82dc6ffffffffff', '82dc77fffffffff', '82dcc7fffffffff', + '82dccffffffffff', '82dcd7fffffffff', '82dce7fffffffff', + '82dceffffffffff', '82dcf7fffffffff', '82dd1ffffffffff', + '82dd47fffffffff', '82dd4ffffffffff', '82dd57fffffffff', + '82dd5ffffffffff', '82dd6ffffffffff', '82dd87fffffffff', + '82dd8ffffffffff', '82dd97fffffffff', '82dd9ffffffffff', + '82ddaffffffffff', '82ddb7fffffffff', '82dec7fffffffff', + '82decffffffffff', '82ded7fffffffff', '82dee7fffffffff', + '82deeffffffffff', '82def7fffffffff', '82df0ffffffffff', + '82df1ffffffffff', '82df47fffffffff', '82df4ffffffffff', + '82df57fffffffff', '82df5ffffffffff', '82df77fffffffff', + '82df8ffffffffff', '82df9ffffffffff', '82e6c7fffffffff', + '82e6cffffffffff', '82e6d7fffffffff', '82e6dffffffffff', + '82e6effffffffff', '82e6f7fffffffff', + ] + + mpoly = h3.cells_to_h3shape(cells, tight=False) + + assert len(mpoly) == 12 + for poly in mpoly: + assert len(poly.holes) == 0 + + assert_cells_roundtrip(cells) + + +def test_equator_cells(): + """Continuous band of cells overlapping the equator. + """ + cells = [ + '81807ffffffffff', '817efffffffffff', '81723ffffffffff', + '817ebffffffffff', '817c3ffffffffff', '817e3ffffffffff', + '817a3ffffffffff', '8166fffffffffff', '8172bffffffffff', + '816afffffffffff', '81933ffffffffff', '8168fffffffffff', + '8188fffffffffff', '81853ffffffffff', '817f7ffffffffff', + '8180bffffffffff', '81783ffffffffff', '81743ffffffffff', + '8170bffffffffff', '8173bffffffffff', '8179bffffffffff', + '817cbffffffffff', '8188bffffffffff', '81857ffffffffff', + '816f7ffffffffff', '8177bffffffffff', '81617ffffffffff', + '816f3ffffffffff', '8174bffffffffff', '8180fffffffffff', + '817a7ffffffffff', '81767ffffffffff', '81757ffffffffff', + '81957ffffffffff', '81787ffffffffff', '81847ffffffffff', + '81653ffffffffff', '817bbffffffffff', '816cfffffffffff', + '816abffffffffff', '815f3ffffffffff', '817c7ffffffffff', + '8168bffffffffff', '818cbffffffffff', '818cfffffffffff', + '818afffffffffff', '8174fffffffffff', '8172fffffffffff', + '8170fffffffffff', '816fbffffffffff', '81657ffffffffff', + '816c7ffffffffff', '8186bffffffffff', '81763ffffffffff', + '818a7ffffffffff', '8186fffffffffff', '81707ffffffffff', + '8182bffffffffff', '818f3ffffffffff', '8182fffffffffff', + ] + mpoly = h3.cells_to_h3shape(cells, tight=False) + + assert len(mpoly) == 1 + poly = mpoly[0] + assert len(poly.holes) == 1 + + # Roundtrip fails: h3shape_to_cells recovers only 18/60 cells. + # TODO: assert_cells_roundtrip when h3shape_to_cells handles global polygons. + cells2 = h3.h3shape_to_cells(mpoly, 1) + assert len(cells2) == 18 + + +def test_prime_meridian(): + """Continuous band of cells overlapping the prime meridian. + """ + cells = [ + '81efbffffffffff', '81c07ffffffffff', '81d1bffffffffff', + '81097ffffffffff', '8109bffffffffff', '81d0bffffffffff', + '81987ffffffffff', '81017ffffffffff', '81e67ffffffffff', + '81ddbffffffffff', '81ac7ffffffffff', '8158bffffffffff', + '81397ffffffffff', '81593ffffffffff', '81c17ffffffffff', + '81827ffffffffff', '81197ffffffffff', '81eebffffffffff', + '81383ffffffffff', '81dcbffffffffff', '81757ffffffffff', + '81093ffffffffff', '81073ffffffffff', '8159bffffffffff', + '81f17ffffffffff', '81187ffffffffff', '81007ffffffffff', + '81997ffffffffff', '81753ffffffffff', '81033ffffffffff', + '81f2bffffffffff', '8138bffffffffff', + ] + mpoly = h3.cells_to_h3shape(cells, tight=False) + + assert len(mpoly) == 1 + poly = mpoly[0] + assert len(poly.holes) == 0 + assert len(poly.outer) == 128 + + # Roundtrip fails: h3shape_to_cells raises on this global polygon. + # TODO: assert_cells_roundtrip when h3shape_to_cells handles global polygons. with pytest.raises(H3FailedError): - h3.cells_to_h3shape(cells) + h3.h3shape_to_cells(mpoly, 1) + + +def test_anti_meridian(): + """Continuous band of cells overlapping the anti-meridian.""" + cells = [ + '817ebffffffffff', '8133bffffffffff', '81047ffffffffff', + '81f3bffffffffff', '81dbbffffffffff', '8132bffffffffff', + '810cbffffffffff', '81bb3ffffffffff', '81db3ffffffffff', + '81bafffffffffff', '81177ffffffffff', '817fbffffffffff', + '81ba3ffffffffff', '815abffffffffff', '815bbffffffffff', + '81eafffffffffff', '81ed7ffffffffff', '81057ffffffffff', + '819a7ffffffffff', '81eabffffffffff', '819b7ffffffffff', + '81167ffffffffff', '81227ffffffffff', '8171bffffffffff', + '81237ffffffffff', '810dbffffffffff', '81033ffffffffff', + '81f2bffffffffff', '8147bffffffffff', '81f33ffffffffff', + ] + mpoly = h3.cells_to_h3shape(cells, tight=False) + + assert len(mpoly) == 1 + poly = mpoly[0] + assert len(poly.holes) == 0 + assert len(poly.outer) == 117 + + # Roundtrip fails: h3shape_to_cells raises on this global polygon. + # TODO: assert_cells_roundtrip when h3shape_to_cells handles global polygons. + with pytest.raises(H3FailedError): + h3.h3shape_to_cells(mpoly, 1) + + +def test_issue_482_with_antimeridian(): + """From https://github.com/uber/h3-py/issues/482 + + Test three versions: the full set, removal of antimeridian overlaps, and removal + of one cell by the north pole also causing roundtrip issues. + + Roundtrip works after removal of all troublesome cells. + """ + cells0 = { + '8001fffffffffff', '8005fffffffffff', '8009fffffffffff', '800bfffffffffff', + '8011fffffffffff', '8015fffffffffff', '8017fffffffffff', '801ffffffffffff', + '8021fffffffffff', '8025fffffffffff', '802dfffffffffff', '802ffffffffffff', + '8031fffffffffff', '8033fffffffffff', '803dfffffffffff', '803ffffffffffff', + '8041fffffffffff', '8043fffffffffff', '804bfffffffffff', '804ffffffffffff', + '8053fffffffffff', '8059fffffffffff', '8061fffffffffff', '8063fffffffffff', + '8065fffffffffff', '8069fffffffffff', '806bfffffffffff', '8073fffffffffff', + '8077fffffffffff', + } + + # remove cells that overlap the antimeridian + cells1 = cells0 - {'8005fffffffffff', '8017fffffffffff', '8033fffffffffff'} + + # remove cell that is very close to north pole (maybe touches) + cells2 = cells1 - {'8001fffffffffff'} + + # --- cells0: all 29 cells --- + mpoly = h3.cells_to_h3shape(cells0, tight=False) + assert len(mpoly) == 1 + assert len(mpoly[0].holes) == 0 + assert len(mpoly[0].outer) == 37 + + # Roundtrip fails: recovers ~23/29, and not even a subset of the original. + # TODO: assert_cells_roundtrip when h3shape_to_cells handles global polygons. + cells_out = h3.h3shape_to_cells(mpoly, 0) + assert len(cells_out) < len(cells0) # exact count differs by OS + assert not (set(cells_out) <= cells0) + + # --- cells1: remove antimeridian-crossing cells (26 remaining) --- + mpoly = h3.cells_to_h3shape(cells1, tight=False) + assert len(mpoly) == 1 + assert len(mpoly[0].holes) == 0 + assert len(mpoly[0].outer) == 37 + + # Roundtrip fails: recovers 18/26, and not even a subset of the original. + # TODO: assert_cells_roundtrip when h3shape_to_cells handles global polygons. + cells_out = h3.h3shape_to_cells(mpoly, 0) + assert len(cells_out) == 18 + assert not (set(cells_out) <= cells1) + + # --- cells2: also remove near-pole cell (25 remaining) --- + mpoly = h3.cells_to_h3shape(cells2, tight=False) + assert len(mpoly) == 1 + assert len(mpoly[0].holes) == 0 + assert len(mpoly[0].outer) == 37 + + # Roundtrip succeeds. + assert_cells_roundtrip(list(cells2)) From 13c17b5067133bd3c2ab6e68c31a10e100e68930 Mon Sep 17 00:00:00 2001 From: zabop Date: Thu, 26 Mar 2026 21:59:38 +0100 Subject: [PATCH 31/63] make docstring reflect what the function does (#486) --- src/h3/api/basic_int/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/h3/api/basic_int/__init__.py b/src/h3/api/basic_int/__init__.py index 47f1c7e..1086a63 100644 --- a/src/h3/api/basic_int/__init__.py +++ b/src/h3/api/basic_int/__init__.py @@ -160,7 +160,7 @@ def is_valid_cell(h): def is_valid_directed_edge(edge): """ - Validates an H3 unidirectional edge. + Validates an H3 directed edge. Returns ------- From f175d06282b1f6933c9e5e61362d396b73a9b9c2 Mon Sep 17 00:00:00 2001 From: Marco Barbosa Date: Mon, 20 Apr 2026 02:24:41 -0300 Subject: [PATCH 32/63] updates readme.md clone instructions (#489) --- dev_notes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev_notes.md b/dev_notes.md index d8635b0..65b4f62 100644 --- a/dev_notes.md +++ b/dev_notes.md @@ -6,7 +6,8 @@ This repo uses [`just`](https://github.com/casey/just) for running common develo To get started: -- `git clone git@github.com:uber/h3-py.git` +- `git clone --recurse-submodules git@github.com:uber/h3-py.git` + - or fork the repository and `git clone --recurse-submodules https://github.com/{username}/h3-py.git` - `cd h3-py` - `just lint` - `just test` From 40910c1291bf94df166044d496d9c288a23cb768 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Thu, 28 May 2026 12:36:48 -0700 Subject: [PATCH 33/63] prep for v4.5.0a3 (#491) * bump C lib to v4.5.0 * add (#491) --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- src/h3/_cy/h3lib.pxd | 11 ++++++++--- src/h3lib | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64fe3e3..546f179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ avoid adding features or APIs which do not map onto the ## Unreleased +## [4.5.0a3] - 2026-05-22 + +- Update `h3lib` to v4.5.0 release (#491) + ## [4.5.0a2] - 2026-02-27 - `cells_to_h3shape`/`cells_to_geo` now handle all valid cell sets, including diff --git a/pyproject.toml b/pyproject.toml index 1da4918..754413f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.5.0a2' +version = '4.5.0a3' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} diff --git a/src/h3/_cy/h3lib.pxd b/src/h3/_cy/h3lib.pxd index 7dfa0c5..6ee3b41 100644 --- a/src/h3/_cy/h3lib.pxd +++ b/src/h3/_cy/h3lib.pxd @@ -156,9 +156,6 @@ cdef extern from 'h3api.h': double greatCircleDistanceKm(const LatLng *a, const LatLng *b) nogil double greatCircleDistanceM(const LatLng *a, const LatLng *b) nogil - H3Error cellsToMultiPolygon(const H3int *cells, const int64_t numCells, GeoMultiPolygon *out) - void destroyGeoMultiPolygon(GeoMultiPolygon *mpoly) - H3Error maxPolygonToCellsSize(const GeoPolygon *geoPolygon, int res, uint32_t flags, uint64_t *count) H3Error polygonToCells(const GeoPolygon *geoPolygon, int res, uint32_t flags, H3int *out) @@ -184,3 +181,11 @@ cdef extern from 'h3api.h': # void h3ToString(H3int h, char *str, size_t sz) # void getH3intesFromUnidirectionalEdge(H3int edge, H3int *originDestination) + + +# cellsToMultiPolygon and destroyGeoMultiPolygon are temporarily excluded +# from the public API, so we use an internal header until they're moved +# back into h3api.h +cdef extern from 'cellsToMultiPoly.h': + H3Error cellsToMultiPolygon(const H3int *cells, const int64_t numCells, GeoMultiPolygon *out) + void destroyGeoMultiPolygon(GeoMultiPolygon *mpoly) diff --git a/src/h3lib b/src/h3lib index a9c0a2e..1b536c3 160000 --- a/src/h3lib +++ b/src/h3lib @@ -1 +1 @@ -Subproject commit a9c0a2ec7869fa01772dcebdf930590469910600 +Subproject commit 1b536c34225191ba24a75a840f634d4a48c3b206 From a663439e0e4c6c2887da8d3af0608156a7f07165 Mon Sep 17 00:00:00 2001 From: Jongbin Jung Date: Fri, 29 May 2026 09:15:58 -0700 Subject: [PATCH 34/63] Prep for v4.5.0 release --- CHANGELOG.md | 6 +++++- pyproject.toml | 2 +- readme.md | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 546f179..651c76c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ avoid adding features or APIs which do not map onto the ## Unreleased +## [4.5.0] - 2026-05-29 + +- Final v4.5 release includes all v4.5.x changes below + ## [4.5.0a3] - 2026-05-22 - Update `h3lib` to v4.5.0 release (#491) @@ -152,7 +156,7 @@ Beta release; feedback welcome! - Website and API documentation; along with docstring cleanup. - Add support for linters and IDE tooling (#213) - Remove Py 3.5 wheel for Windows (#214) -- Py 3.10 wheels and on more architectures (#220, #221, #223, #225) +- Py 3.10 wheels and on more architectures (#220, #221, #223, #225) - Greatly reduce sdist size (#227, #229) ## [3.7.3] - 2021-06-12 diff --git a/pyproject.toml b/pyproject.toml index 754413f..f3304b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'scikit_build_core.build' [project] name = 'h3' -version = '4.5.0a3' +version = '4.5.0' description = "Uber's hierarchical hexagonal geospatial indexing system" readme = 'readme.md' license = {file = 'LICENSE'} diff --git a/readme.md b/readme.md index 843324e..8cb052b 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ [![PyPI version](https://badge.fury.io/py/h3.svg)](https://badge.fury.io/py/h3) [![PyPI downloads](https://img.shields.io/pypi/dm/h3.svg)](https://pypistats.org/packages/h3) [![conda](https://img.shields.io/conda/vn/conda-forge/h3-py.svg)](https://anaconda.org/conda-forge/h3-py) -[![version](https://img.shields.io/badge/h3-v4.4.1-blue.svg)](https://github.com/uber/h3/releases/tag/v4.4.1) +[![version](https://img.shields.io/badge/h3-v4.5.0-blue.svg)](https://github.com/uber/h3/releases/tag/v4.5.0) [![version](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/uber/h3-py/blob/master/LICENSE) [![Tests](https://github.com/uber/h3-py/workflows/tests/badge.svg)](https://github.com/uber/h3-py/actions) From 7d1df6e070a9c4794d31199ef945322554aca2ad Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Fri, 15 May 2026 00:51:22 +0900 Subject: [PATCH 35/63] 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 36/63] 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 37/63] 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 38/63] 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 39/63] 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 40/63] 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 41/63] 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 42/63] 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 43/63] 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 44/63] 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 45/63] 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 46/63] 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 47/63] 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 48/63] 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 49/63] 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 50/63] 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 51/63] 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 52/63] 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 53/63] 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 54/63] 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 55/63] 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 56/63] 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 57/63] 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 58/63] 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 59/63] 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 60/63] 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 61/63] 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 62/63] 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 63/63] 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',