Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow string subtypes as H3str #411

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion src/h3/api/basic_int/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def str_to_int(h):
int
Unsigned 64-bit integer
"""
return _cy.str_to_int(str(h))
return _cy.str_to_int(h)


def int_to_str(x):
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)
Loading