Skip to content

Read of netCDF file fails with units attribute that is not of type string #4634

Closed
@ajwdewit

Description

@ajwdewit

When opening a netCDF file which has a variable that has a units attribute with a definition of integer 1, xarray fails to open the file:

~/bin/miniconda3/envs/py37_crucial/lib/python3.8/site-packages/xarray/conventions.py in _update_bounds_attributes(variables)
    379     for v in variables.values():
    380         attrs = v.attrs
--> 381         has_date_units = "units" in attrs and "since" in attrs["units"]
    382         if has_date_units and "bounds" in attrs:
    383             if attrs["bounds"] in variables:

TypeError: argument of type 'numpy.int64' is not iterable

This because line 381 will search for the word "since" in an integer type which fails. Of course assigning a integer as units attribute is not wise, but some people tend to assign integer 1 for variables which have no units.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions