Skip to content

Commit

Permalink
Merge pull request #21 from DahnJ/fix/dj-parent-level-0
Browse files Browse the repository at this point in the history
Fix: `h3_to_parent(0)` correctly creates column `h3_00`
  • Loading branch information
DahnJ authored Mar 19, 2023
2 parents 52a3111 + 01f6722 commit 3f38f8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion h3pandas/h3pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ def h3_to_parent(self, resolution: int = None) -> AnyDataFrame:
881e2659c3fffff 1 851e265bfffffff
"""
# TODO: Test `h3_parent` case
column = self._format_resolution(resolution) if resolution else "h3_parent"
column = (
self._format_resolution(resolution)
if resolution is not None
else "h3_parent"
)
return self._apply_index_assign(
wrapped_partial(h3.h3_to_parent, res=resolution), column
)
Expand Down
16 changes: 15 additions & 1 deletion tests/test_h3pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,27 @@ def test_h3_to_geo_boundary_wrong_index(self, indexed_dataframe):


class TestH3ToParent:
def test_h3_to_parent(self, h3_dataframe_with_values):
def test_h3_to_parent_level_1(self, h3_dataframe_with_values):
h3_parent = "811f3ffffffffff"
result = h3_dataframe_with_values.h3.h3_to_parent(1)
expected = h3_dataframe_with_values.assign(h3_01=h3_parent)

pd.testing.assert_frame_equal(expected, result)

def test_h3_to_direct_parent(self, h3_dataframe_with_values):
h3_parents = ["881f1d4817fffff", "881f1d4817fffff", "881f1d4811fffff"]
result = h3_dataframe_with_values.h3.h3_to_parent()
expected = h3_dataframe_with_values.assign(h3_parent=h3_parents)

pd.testing.assert_frame_equal(expected, result)

def test_h3_to_parent_level_0(self, h3_dataframe_with_values):
h3_parent = "801ffffffffffff"
result = h3_dataframe_with_values.h3.h3_to_parent(0)
expected = h3_dataframe_with_values.assign(h3_00=h3_parent)

pd.testing.assert_frame_equal(expected, result)


class TestH3ToCenterChild:
def test_h3_to_center_child(self, indexed_dataframe):
Expand Down

0 comments on commit 3f38f8f

Please sign in to comment.