Skip to content

Commit

Permalink
Support str-like values for str_to_int (#408)
Browse files Browse the repository at this point in the history
* Add failing test

* Explicitly convert to str before calling _cy.str_to_int
  • Loading branch information
jongbinjung authored and ajfriend committed Oct 5, 2024
1 parent e9b3ff5 commit 696e753
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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(h)
return _cy.str_to_int(str(h))


def int_to_str(x):
Expand Down
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 696e753

Please sign in to comment.