-
Notifications
You must be signed in to change notification settings - Fork 132
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
Added Bindings for Vertex-Related Functions #388
Conversation
This is great. Thanks for the PR! I'll take a look. |
CHANGELOG.md
Outdated
@@ -16,7 +16,9 @@ avoid adding features or APIs which do not map onto the | |||
|
|||
## Unreleased | |||
|
|||
- None | |||
## [4.0.0b6] - 2024-08-23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just put this under ## Unreleased
for now, since we'll publish as a separate step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
src/h3/_cy/latlng.pyx
Outdated
@@ -245,3 +246,46 @@ cpdef double great_circle_distance( | |||
raise ValueError('Unknown unit: {}'.format(unit)) | |||
|
|||
return d | |||
|
|||
# todo: one might want to move the following to a separate vertex.pyx file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm supportive of moving this to a separate vertex.pyx
file in this PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but I thought that would be a larger change of structure... I wrote this comment in case there would be more vertex-related functions in the future. IMHO the current structure is good enough, but I can move it to a separate file as well if it's very beneficial :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate you asking! I think your suggestion to move the vertex code to its own file is a good one. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'd do so.
src/h3/api/basic_int/__init__.py
Outdated
Return a list of vertices of an H3 cell. The list will always be of length 6. | ||
If a pentagon is entered, the last element will be 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Python world, I'd rather have us dynamically size the array: a hex should return an array of length 6, and a pentagon should return an array of length 5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I fixed array length to 6 only to align with the official docs... I'll change this.
src/h3/api/basic_int/__init__.py
Outdated
|
||
Returns | ||
------- | ||
A list of vertices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think we should have used "vertices" in H3, we decided to go with "vertexes". As a result, I think we should try to be consistent in the code and docs and only use "vertexes".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK! :-)
src/h3/api/basic_int/__init__.py
Outdated
if isinstance(v, str): | ||
v = str_to_int(v) | ||
return _cy.vertex_to_latlng(v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use _in_scalar()
so that this function will work as expected for the other APIs (basic_int
, basic_str
, etc.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
src/h3/api/basic_int/__init__.py
Outdated
if isinstance(v, str): | ||
v = str_to_int(v) | ||
return _cy.is_valid_vertex(v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use _in_scalar()
here as well. See how we do it in is_valid_cell
, is_valid_directed_edge
, and is_pentagon
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
tests/test_h3.py
Outdated
|
||
def test_is_valid_vertex(): | ||
assert h3.is_valid_vertex('2114c3ffffffffff') | ||
assert h3.is_valid_vertex(2455495337847029759) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should expect this to fail for the (default) string API because a string is expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
Added some minor comments, but overall this looks great. Thanks! |
tests/test_h3.py
Outdated
latlng = h3.vertex_to_latlng('2114c3ffffffffff') | ||
assert latlng == approx((24.945215618732814, -70.33904370008679)) | ||
latlng = h3.vertex_to_latlng(2455495337847029759) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't expect any single API to be able to handle both str
and int
inputs. The current design expects them to select an API explicitly, like h3.api.basic_int
or h3.api.basic_str
(the default).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I'll just leave the string tests, then.
src/h3/api/basic_int/__init__.py
Outdated
""" | ||
h = _in_scalar(h) | ||
mv = _cy.cell_to_vertexes(h) | ||
arr = [str_to_int(a) for a in _out_collection(mv)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making adjustments, but this will still return int
s for each API. We want the output to depend on the API:
- list of
int
forh3.api.basic_int
- list of
str
forh3.api.basic_str
numpy.array
forh3.api.numpy_int
memoryview
ofint
forh3.api.memview_int
To do that, the last operation should be _out_collcation(mv)
. The _remove_zeros()
function should help with this: https://github.com/uber/h3-py/blob/master/src/h3/_cy/memory.pyx#L113
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line still needed? It looks as if you can return _out_collection(mv)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have rewritten in my newest commit (yesterday)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github is still showing this comment as up-to-date, could you double check your commit has been pushed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, thank you! Fixed.
Update: All previously proposed comments by @ajfriend have now been resolved! :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajfriend Coverage test seems to be failing due to a Codecov token issue, is that on your radar?
src/h3/api/basic_int/__init__.py
Outdated
""" | ||
h = _in_scalar(h) | ||
mv = _cy.cell_to_vertexes(h) | ||
arr = [str_to_int(a) for a in _out_collection(mv)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github is still showing this comment as up-to-date, could you double check your commit has been pushed?
While I'm trying to fix the codedov issue, @Shiran-Yuan, would you mind also adding these functions to the docs? It should just involve creating a new section for these vertex functions in https://github.com/uber/h3-py/blob/master/docs/api_quick.md |
I see, no problem, I'll go add that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thanks for the PR! I think we can land without the codecov since it isn't clear when that will get resolved. I'll leave this up for a bit to see if anyone else has comments.
* Update CHANGELOG.md * Update h3lib.pxd * Update latlng.pxd * Update latlng.pyx * Update util.pxd * Update util.pyx * Update _version.py * Update __init__.py * Update __init__.py * Update test_h3.py * Update __init__.py * Update test_h3.py * Update CHANGELOG.md * Update __init__.py * Update test_h3.py * Update _version.py * Update test_h3.py * Update __init__.py * Update CMakeLists.txt * Update latlng.pxd * Update latlng.pyx * Create vertex.pxd * Create vertex.pyx * Update __init__.py * Update test_h3.py * Update __init__.py * Update api_quick.md
* trying a scikit-build-core setup * trying things * vendor FindCython * fix build * remove unused * cython tests working * fix lint action * coverage fix * drop annotation stuff for now, because i can't get it working * book building * all target * try again * don't install all * numpy! * pip install h3.tar.gz[test] * drop wheel builds for 3.6 and 3.7 * move coverage config to pyproject.toml * remove requirements-dev.txt * remove cmake from the build system requirements * single sourcing the version number in _version.py * i think scikitbuild-core doesn't work with dynamic = ['version']. try something else * uber's * alphabetical files in cmakelists.txt * tidy up files in the sdist * move pytest config to pyproject.toml * CIBW_TEST_COMMAND: pytest * CIBW_TEST_COMMAND: pytest {project}/tests * CIBW_TEST_REQUIRES: pytest pytest-cov numpy * get better coverage on the testing code * fix api reference link (#385) * Added Bindings for Vertex-Related Functions (#388) * Update CHANGELOG.md * Update h3lib.pxd * Update latlng.pxd * Update latlng.pyx * Update util.pxd * Update util.pyx * Update _version.py * Update __init__.py * Update __init__.py * Update test_h3.py * Update __init__.py * Update test_h3.py * Update CHANGELOG.md * Update __init__.py * Update test_h3.py * Update _version.py * Update test_h3.py * Update __init__.py * Update CMakeLists.txt * Update latlng.pxd * Update latlng.pyx * Create vertex.pxd * Create vertex.pyx * Update __init__.py * Update test_h3.py * Update __init__.py * Update api_quick.md * Bump actions/download-artifact from 4.1.4 to 4.1.7 in /.github/workflows (#392) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 4.1.4 to 4.1.7. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](actions/download-artifact@v4.1.4...v4.1.7) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * prep for v4.0.0b6 release (#394) * alphabetical files in cmakelists.txt * single * test with numpy>=2 * drop lower bound on numpy version --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Isaac Brodsky <[email protected]> Co-authored-by: Pieter Provoost <[email protected]> Co-authored-by: Shiran Yuan <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Added bindings and associated tests for the functions
cellToVertex
,cellToVertexes
,vertexToLatLng
,isValidVertex
, andcheck_vertex
per #323, ending theh3-py
repo's longstanding disagreement with official documentation.Vertices are returned as integers by default in
cellToVertex
andcellToVertexes
, but inputs tovertexToLatLng
andisValidVertex
can be either integers or strings (the two forms are equivalent viaint_to_str
andstr_to_int
).Affected files:
src/h3/_cy/__init__.py
: added declarationslatlng.pxd
andlatlng.pyx
: wrote the functionsutil.pxd
andutil.pyx
: addedcheck_vertex
test_h3.py
: added testssrc/h3/api/basic_int/__init__.py
(and its aliases): added api accessh3lib.pxd
: added declarations for the original functions inh3lib
CHANGELOG.md
and_version.py
: suggested version number4.0.0b6