NCAS-CMS / cfdm

A Python reference implementation of the CF data model
http://ncas-cms.github.io/cfdm
MIT License
28 stars 11 forks source link

`cf.Field.cell_methods` returns incorrect results when an invalid identifer is provided #299

Open davidhassell opened 3 months ago

davidhassell commented 3 months ago

At cfdm v1.11.1.0, when an invalid selection is passed to cfdm.Field.cell_methods, all cell method constructs are returned, rather than none of them as expected:

>>> import cfdm
>>> f = cfdm.example_field(1)
>>> print(f.cell_methods())  # CORRECT output:
Constructs:
{'cellmethod0': <CellMethod: domainaxis1: domainaxis2: mean where land (interval: 0.1 degrees)>,
 'cellmethod1': <CellMethod: domainaxis3: maximum>}
>>> print(f.cell_methods('bad identifier'))  # WRONG output, expected: Constructs: {}
Constructs:
{'cellmethod0': <CellMethod: domainaxis1: domainaxis2: mean where land (interval: 0.1 degrees)>,
 'cellmethod1': <CellMethod: domainaxis3: maximum>}