Skip to content

Can not initialize Cdo object for CDO version 1.9.10  #46

Description

@pjpetersik

I am working with the python CDO binding in a docker container which runs a debian bullseye distribution (python:3.9.15-slim-bullseye). I installed the cdo biniary using apt-get install cdo which installs CDO version 1.9.10 (https://packages.debian.org/bullseye/cdo).

When I call Cdo() I get an IndexError with a Traceback that ends as follows:

 File "/usr/local/lib/python3.9/site-packages/cdo.py", line 190, in __init__
self.operators = self.__getOperators()
File "/usr/local/lib/python3.9/site-packages/cdo.py", line 341, in __getOperators
operators[op] = int(ios[i][1:len(ios[i]) - 1].split('|')[1])
IndexError: list index out of range

This is caused by an unexpected behaviour of cdo --operators. When running cdo --operators in the command line, I get an unexpected output in the first line of the output:

PRE-MAIN-DEBUG Registering library [eckit] with address [0x7fa77f2ad9a0]
abs Absolute value (1|1)
acos Arc cosine (1|1)
add Add two fields (2|1)
addc Add a constant (1|1)
addtrend Add trend (3|1)
...

So the first line of the output is actually not an operator. I can monkey patch this error with the following code which basically jumps the first line of the output of cdo --operators:

importosimportsubprocessfromcdoimportCdoclassCdoMonkeyPatch(Cdo):
def__getOperators(self): # {{{operators= {}
proc=subprocess.Popen([self.CDO, '--operators'],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
ret=proc.communicate()
ops=list(map(lambdax: x.split(' ')[0], ret[0].decode(
"utf-8")[0:-1].split(os.linesep)))
ios=list(map(lambdax: x.split(' ')
[-1], ret[0].decode("utf-8")[0:-1].split(os.linesep)))
fori, opinenumerate(ops):
ifi!=0:
operators[op] =int(ios[i][1:len(ios[i]) -1].split('|')[1])
returnoperators# }}}

Is there something wrong with my CDO installation?

BTW: This error did not appear when I was using the python:3.8.13-slim-buster image for which CDO version 1.9.6 is installed by apt-get install cdo (https://packages.debian.org/buster/cdo).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions