Skip to content

Commit

Permalink
Allow string subtypes as H3str (#411)
Browse files Browse the repository at this point in the history
* Add test for string subtypes

* Allow string subtypes as H3str
  • Loading branch information
jongbinjung authored Oct 6, 2024
1 parent 91ab2bf commit 24074ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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)

0 comments on commit 24074ae

Please sign in to comment.