Skip to content

Commit 3f38f8f

Browse files
authored
Merge pull request #21 from DahnJ/fix/dj-parent-level-0
Fix: `h3_to_parent(0)` correctly creates column `h3_00`
2 parents 52a3111 + 01f6722 commit 3f38f8f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

h3pandas/h3pandas.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ def h3_to_parent(self, resolution: int = None) -> AnyDataFrame:
324324
881e2659c3fffff 1 851e265bfffffff
325325
"""
326326
# TODO: Test `h3_parent` case
327-
column = self._format_resolution(resolution) if resolution else "h3_parent"
327+
column = (
328+
self._format_resolution(resolution)
329+
if resolution is not None
330+
else "h3_parent"
331+
)
328332
return self._apply_index_assign(
329333
wrapped_partial(h3.h3_to_parent, res=resolution), column
330334
)

tests/test_h3pandas.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,27 @@ def test_h3_to_geo_boundary_wrong_index(self, indexed_dataframe):
145145

146146

147147
class TestH3ToParent:
148-
def test_h3_to_parent(self, h3_dataframe_with_values):
148+
def test_h3_to_parent_level_1(self, h3_dataframe_with_values):
149149
h3_parent = "811f3ffffffffff"
150150
result = h3_dataframe_with_values.h3.h3_to_parent(1)
151151
expected = h3_dataframe_with_values.assign(h3_01=h3_parent)
152152

153153
pd.testing.assert_frame_equal(expected, result)
154154

155+
def test_h3_to_direct_parent(self, h3_dataframe_with_values):
156+
h3_parents = ["881f1d4817fffff", "881f1d4817fffff", "881f1d4811fffff"]
157+
result = h3_dataframe_with_values.h3.h3_to_parent()
158+
expected = h3_dataframe_with_values.assign(h3_parent=h3_parents)
159+
160+
pd.testing.assert_frame_equal(expected, result)
161+
162+
def test_h3_to_parent_level_0(self, h3_dataframe_with_values):
163+
h3_parent = "801ffffffffffff"
164+
result = h3_dataframe_with_values.h3.h3_to_parent(0)
165+
expected = h3_dataframe_with_values.assign(h3_00=h3_parent)
166+
167+
pd.testing.assert_frame_equal(expected, result)
168+
155169

156170
class TestH3ToCenterChild:
157171
def test_h3_to_center_child(self, indexed_dataframe):

0 commit comments

Comments
 (0)