Skip to content

Commit 4085ea5

Browse files
committed
PR #200 change back to apply_dimension with dimension=bands
1 parent 329a4ce commit 4085ea5

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

openeo_driver/datacube.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class DriverVectorCube:
216216
These components are "joined" on the GeoPandas dataframe's index and DataArray first dimension
217217
"""
218218
DIM_GEOMETRIES = "geometries"
219+
DIM_BANDS = "bands"
219220
FLATTEN_PREFIX = "vc"
220221

221222
def __init__(
@@ -519,7 +520,7 @@ def apply_dimension(
519520

520521
if single_run_udf:
521522
# Process with single "run_udf" node
522-
if self._cube is None and dimension == self.DIM_GEOMETRIES and target_dimension is None:
523+
if dimension == self.DIM_BANDS and target_dimension is None:
523524
log.warning(
524525
f"Using experimental feature: DriverVectorCube.apply_dimension along dim {dimension} and empty cube"
525526
)
@@ -535,14 +536,18 @@ def apply_dimension(
535536
result_data = env.backend_implementation.processing.run_udf(udf=single_run_udf.udf, data=udf_data)
536537
log.info(f"[run_udf] UDF resulted in {result_data!r}")
537538

538-
if isinstance(result_data, openeo.udf.UdfData):
539-
result_features = result_data.get_feature_collection_list()
540-
if result_features and len(result_features) == 1:
541-
return DriverVectorCube(geometries=result_features[0].data)
542-
raise ValueError(f"Could not handle UDF result: {result_data}")
543-
544-
raise FeatureUnsupportedException()
545-
539+
if not isinstance(result_data, openeo.udf.UdfData):
540+
raise ValueError(f"UDF should return UdfData, but got {type(result_data)}")
541+
result_features = result_data.get_feature_collection_list()
542+
if not (result_features and len(result_features) == 1):
543+
raise ValueError(
544+
f"UDF should return single feature collection but got {result_features and len(result_features)}"
545+
)
546+
return DriverVectorCube(geometries=result_features[0].data)
547+
548+
raise FeatureUnsupportedException(
549+
message=f"DriverVectorCube.apply_dimension with {dimension=} and {bool(single_run_udf)=}"
550+
)
546551

547552

548553
class DriverMlModel:

tests/test_vectorcube.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def test_buffer_points(self):
454454
}
455455
)
456456

457-
def test_apply_dimension_run_udf(self, vc, backend_implementation):
457+
def test_apply_dimension_run_udf_change_geometry(self, vc, backend_implementation):
458458
udf = textwrap.dedent(
459459
"""
460460
from openeo.udf import UdfData, FeatureCollection
@@ -475,7 +475,7 @@ def process_geometries(udf_data: UdfData) -> UdfData:
475475
}
476476
}
477477
env = EvalEnv({"backend_implementation": backend_implementation})
478-
result = vc.apply_dimension(process=callback, dimension="geometries", env=env)
478+
result = vc.apply_dimension(process=callback, dimension="bands", env=env)
479479
assert isinstance(result, DriverVectorCube)
480480
feature_collection = result.to_geojson()
481481
assert feature_collection == DictSubSet(

0 commit comments

Comments
 (0)