Skip to content

Error on reading files with conformant Conventions value 'CF-1.*-draft' #297

@sadielbartholomew

Description

@sadielbartholomew

The working CF Conformance document. i.e. the one in draft form, states that (using the example of the current working document i.e. v.1.12)

Files that conform to the CF version 1.12 draft conventions must indicate this by setting the global Conventions attribute to contain the CF string value "CF-1.12-draft".

This clearly gets changed to 'CF-1.12' when the version is released such that it is no longer draft form, but to me that implies that "CF-1.12-draft" and similarly any 'CF-<valid version string>-draft' value should strictly be a conformant value for the Conventions global attribute. However, when we use cfdm (current main branch, and same for 1.11.1.0/last release) to read in such a file, it errors:

>>> import cfdm
>>> import netCDF4
>>> f = cfdm.example_field(0)
>>> cfdm.write(f, "delme.nc")
>>> n = netCDF4.Dataset("delme.nc", "a")
>>> n.Conventions
'CF-1.11'
>>> n.Conventions = "CF-1.12-draft"
>>> n.Conventions
'CF-1.12-draft'
>>> n.close()
>>> g = cfdm.read("delme.nc")[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slb93/git-repos/cfdm/cfdm/read_write/read.py", line 328, in read
    fields = netcdf.read(
             ^^^^^^^^^^^^
  File "/home/slb93/git-repos/cfdm/cfdm/decorators.py", line 171, in verbose_override_wrapper
    return method_with_verbose_kwarg(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/slb93/git-repos/cfdm/cfdm/read_write/netcdf/netcdfread.py", line 1056, in read
    g["file_version"] = Version(file_version)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/home/slb93/miniconda3/lib/python3.11/site-packages/packaging/version.py", line 198, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '1.12-draft'

Whereas such a file should be able to be read in without issue. This can be addressed as part of my PR #296.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdataset readRelating to reading datasets

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions