@@ -235,7 +235,9 @@ def run_udf_code(code: str, data: UdfData) -> UdfData:
235235 raise OpenEoUdfException ("No UDF found." )
236236
237237
238- def execute_local_udf (udf : Union [str , openeo .UDF ], datacube : Union [str , xarray .DataArray , XarrayDataCube ], fmt = 'netcdf' ):
238+ def execute_local_udf (
239+ udf : Union [str , openeo .UDF ], datacube : Union [str , pathlib .Path , xarray .DataArray , XarrayDataCube ], fmt = "netcdf"
240+ ):
239241 """
240242 Locally executes an user defined function on a previously downloaded datacube.
241243
@@ -244,8 +246,8 @@ def execute_local_udf(udf: Union[str, openeo.UDF], datacube: Union[str, xarray.D
244246 :param fmt: format of the file if datacube is string
245247 :return: the resulting DataCube
246248 """
247- if isinstance (udf , openeo . UDF ):
248- udf = udf . code
249+ if isinstance (udf , str ):
250+ udf = openeo . UDF ( code = udf )
249251
250252 if isinstance (datacube , (str , pathlib .Path )):
251253 d = XarrayDataCube .from_file (path = datacube , fmt = fmt )
@@ -266,13 +268,13 @@ def execute_local_udf(udf: Union[str, openeo.UDF], datacube: Union[str, xarray.D
266268 .astype (numpy .float64 )
267269 )
268270 # wrap to udf_data
269- udf_data = UdfData (datacube_list = [d ])
271+ udf_data = UdfData (datacube_list = [d ], user_context = udf . context )
270272
271273 # TODO: enrich to other types like time series, vector data,... probalby by adding named arguments
272274 # signature: UdfData(proj, datacube_list, feature_collection_list, structured_data_list, ml_model_list, metadata)
273275
274276 # run the udf through the same routine as it would have been parsed in the backend
275- result = run_udf_code (udf , udf_data )
277+ result = run_udf_code (udf . code , udf_data )
276278 return result
277279
278280
0 commit comments