Open-EO / openeo-python-client

Python client API for OpenEO
https://open-eo.github.io/openeo-python-client/
Apache License 2.0
156 stars 42 forks source link

JSON serialization bug with `if_` #470

Closed soxofaan closed 1 year ago

soxofaan commented 1 year ago

issue reported by @mbuchhorn

minimal reproduction snippet:

import openeo
from openeo.processes import if_

cube = connection.load_collection("CGLS_GDMP300_V1_GLOBAL")
cube = if_(True, cube, cube)
cube = cube.apply_dimension(process=openeo.UDF(code="def x(): pass"), dimension='t')

cube.print_json()
# - > TypeError: Object of type UDF is not JSON serializable

Dropping the if_ line makes it work again

soxofaan commented 1 year ago

workaround with current version of python client is to replace the cube = if_(True, cube, cube) with

cube = cube.process(process_id="if", arguments={"value": True, "accept": cube, "reject": cube})
mbuchhorn commented 1 year ago

This UDP with same _if and UDF call works: https://github.com/integratedmodelling/OpenEO-UDP-UDF-catalogue/blob/main/UDP/UDP_CORINE_arable_mask.py

only difference: "apply_dimension" instead of apply in the not working version

soxofaan commented 1 year ago

@mbuchhorn no it's the other if_ in your original failing code:

cube = if_(gte(param_year, 2015), datacube1, datacube2)

This (with apply iso apply_dimension) also fails:

cube = connection.load_collection("CGLS_GDMP300_V1_GLOBAL")
cube = if_(True, cube, cube)
cube = cube.apply(process=openeo.UDF(code="def x(): pass"))
soxofaan commented 1 year ago

fixed (will be included in next release 0.23.0)