Skip to content

Commit

Permalink
Merge branch 'master' into aj/v4.1_final
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfriend authored Oct 6, 2024
2 parents c85d2cd + 6d9a5fc commit 4e67f9b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 4 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/coverage-lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: pr-coverage-lint

on:
pull_request:
branches: ['*']

jobs:
tests:
name: Coverage and Lint
runs-on: ubuntu-22.04

steps:
- uses: actions/[email protected]
with:
submodules: recursive

- uses: actions/[email protected]
with:
python-version: 3.11

- name: Install from source
run: |
pip install --upgrade pip setuptools wheel
pip install .[test]
- name: Lint
run: flake8 src/h3 tests

- name: Pylint
# As a test for visibility of API bindings, we want to ensure that pylint has no
# `import-error` warnings for h3 imports.
run: pylint --disable=all --enable=import-error tests/

- name: Coverage
run: |
pip install cython
cythonize tests/test_cython/cython_example.pyx
pytest --cov-report=lcov
- name: Report coverage
uses: romeovs/[email protected]
with:
filter-changed-files: true
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: ./coverage.lcov
2 changes: 0 additions & 2 deletions .github/workflows/coverage-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: coverage-lint
on:
push:
branches: [master]
pull_request:
branches: ['*']

jobs:
tests:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pip-log.txt
# Unit test / coverage reports
.coverage
coverage.xml
coverage.lcov
.tox
nosetests.xml
.noseids
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ None.

- Final v4.1 release inculdes all v4.x changes below.

## [4.1.0b3] - 2024-10-05

- Allow for `str` subtypes, like `numpy.str_` (#408)

## [4.1.0b2] - 2024-09-27

- Add `cell_to_child_pos`, `child_pos_to_cell`, `cell_to_children_size` (#405)
Expand Down
3 changes: 2 additions & 1 deletion src/h3/_cy/h3lib.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# cython: c_string_type=unicode, c_string_encoding=utf8
from cpython cimport bool
from libc.stdint cimport uint32_t, uint64_t, int64_t

ctypedef basestring H3str
ctypedef object H3str

cdef extern from 'h3api.h':
cdef int H3_VERSION_MAJOR
Expand Down
19 changes: 19 additions & 0 deletions tests/test_apis/test_basic_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,22 @@ def test5():

out = h3.grid_disk('8928308280fffff', 1)
assert u.same_set(out, expected)


def test_string_subtypes():

class my_str(str):
pass

expected = [
'89283082873ffff',
'89283082877ffff',
'8928308283bffff',
'89283082807ffff',
'8928308280bffff',
'8928308280fffff',
'89283082803ffff'
]

out = h3.grid_disk(my_str('8928308280fffff'), 1)
assert u.same_set(out, expected)
21 changes: 20 additions & 1 deletion tests/test_apis/test_numpy_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@


def test1():
lat, lng = 37.7752702151959, -122.418307270836,
lat, lng = (
37.7752702151959,
-122.418307270836,
)
assert h3.latlng_to_cell(lat, lng, 9) == 617700169958293503


Expand All @@ -31,3 +34,19 @@ def test_compact_cells():
assert isinstance(cells, np.ndarray)

assert h3.compact_cells(cells) == [h]


def test_numpy_str():
expected = [
617700169957507071,
617700169957769215,
617700169958031359,
617700169958293503,
617700169961177087,
617700169964847103,
617700169965109247,
]
cells = np.array([h3.int_to_str(h) for h in expected])
got = [h3.str_to_int(c) for c in cells]

assert expected == got

0 comments on commit 4e67f9b

Please sign in to comment.