Skip to content

Commit cb651ef

Browse files
committed
PR #200 default to using "properties" dim name
aligns better with load_geojson spec
1 parent 090efca commit cb651ef

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

openeo_driver/datacube.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class DriverVectorCube:
217217
"""
218218
DIM_GEOMETRIES = "geometries"
219219
DIM_BANDS = "bands"
220+
DIM_PROPERTIES = "properties"
220221
FLATTEN_PREFIX = "vc"
221222
COLUMN_SELECTION_ALL = "all"
222223
COLUMN_SELECTION_NUMERICAL = "numerical"
@@ -254,8 +255,7 @@ def from_geodataframe(
254255
data: gpd.GeoDataFrame,
255256
*,
256257
columns_for_cube: Union[List[str], str] = COLUMN_SELECTION_NUMERICAL,
257-
# TODO: change default band name to "properties" (per `load_geojson` spec introduced by https://github.com/Open-EO/openeo-processes/pull/427)
258-
dimension_name: str = DIM_BANDS,
258+
dimension_name: str = DIM_PROPERTIES,
259259
) -> "DriverVectorCube":
260260
"""
261261
Build a DriverVectorCube from given GeoPandas data frame,
@@ -600,7 +600,8 @@ def apply_dimension(
600600

601601
if single_run_udf:
602602
# Process with single "run_udf" node
603-
if dimension == self.DIM_BANDS and target_dimension is None:
603+
# TODO: check provided dimension with actual dimension of the cube
604+
if dimension in (self.DIM_BANDS, self.DIM_PROPERTIES) and target_dimension is None:
604605
log.warning(
605606
f"Using experimental feature: DriverVectorCube.apply_dimension along dim {dimension} and empty cube"
606607
)

tests/test_vectorcube.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,20 @@ def test_from_geodataframe_default(self, gdf):
188188
}
189189
)
190190
cube = vc.get_cube()
191-
assert cube.dims == ("geometries", "bands")
191+
assert cube.dims == ("geometries", "properties")
192192
assert cube.shape == (2, 1)
193-
assert {k: list(v.values) for k, v in cube.coords.items()} == {"geometries": [0, 1], "bands": ["pop"]}
193+
assert {k: list(v.values) for k, v in cube.coords.items()} == {"geometries": [0, 1], "properties": ["pop"]}
194194

195195
@pytest.mark.parametrize(
196196
["columns_for_cube", "expected"],
197197
[
198-
("numerical", {"shape": (2, 1), "coords": {"geometries": [0, 1], "bands": ["pop"]}}),
199-
("all", {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["id", "pop"]}}),
198+
("numerical", {"shape": (2, 1), "coords": {"geometries": [0, 1], "properties": ["pop"]}}),
199+
("all", {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["id", "pop"]}}),
200200
([], None),
201-
(["id"], {"shape": (2, 1), "coords": {"geometries": [0, 1], "bands": ["id"]}}),
202-
(["pop", "id"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["pop", "id"]}}),
201+
(["id"], {"shape": (2, 1), "coords": {"geometries": [0, 1], "properties": ["id"]}}),
202+
(["pop", "id"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["pop", "id"]}}),
203203
# TODO: test specifying non-existent column (to be filled with no-data):
204-
# (["pop", "nopenope"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["pop", "nopenope"]}}),
204+
# (["pop", "nopenope"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["pop", "nopenope"]}}),
205205
],
206206
)
207207
def test_from_geodataframe_columns_for_cube(self, gdf, columns_for_cube, expected):
@@ -237,7 +237,7 @@ def test_from_geodataframe_columns_for_cube(self, gdf, columns_for_cube, expecte
237237
if expected is None:
238238
assert cube is None
239239
else:
240-
assert cube.dims == ("geometries", "bands")
240+
assert cube.dims == ("geometries", "properties")
241241
assert cube.shape == expected["shape"]
242242
assert {k: list(v.values) for k, v in cube.coords.items()} == expected["coords"]
243243

@@ -571,7 +571,9 @@ def test_buffer_points(self):
571571
}
572572
)
573573

574-
def test_apply_dimension_run_udf_change_geometry(self, vc, backend_implementation):
574+
@pytest.mark.parametrize("dimension", ["bands", "properties"])
575+
def test_apply_dimension_run_udf_change_geometry(self, gdf, backend_implementation, dimension):
576+
vc = DriverVectorCube.from_geodataframe(gdf, dimension_name=dimension)
575577
udf = textwrap.dedent(
576578
"""
577579
from openeo.udf import UdfData, FeatureCollection
@@ -592,7 +594,7 @@ def process_geometries(udf_data: UdfData) -> UdfData:
592594
}
593595
}
594596
env = EvalEnv({"backend_implementation": backend_implementation})
595-
result = vc.apply_dimension(process=callback, dimension="bands", env=env)
597+
result = vc.apply_dimension(process=callback, dimension=dimension, env=env)
596598
assert isinstance(result, DriverVectorCube)
597599
feature_collection = result.to_geojson()
598600
assert feature_collection == DictSubSet(

0 commit comments

Comments
 (0)