Skip to content

Saving to netCDF with 0D dimension doesn't work #1352

@andreas-h

Description

@andreas-h

I'm using xarray 0.9.1.

When I have an array

<xarray.Dataset>
Dimensions:       (category: 1, lat: 672, lon: 720, species: 1)
Coordinates:
  * lat           (lat) float64 30.03 30.09 30.16 30.22 30.28 30.34 30.41 ...
  * category      (category) <U3 'agr'
  * species       (species) <U4 'PM10'
  * lon           (lon) float64 -29.94 -29.81 -29.69 -29.56 -29.44 -29.31 ...
Data variables:
    TNO-MACC3_EU  (lon, lat) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...

and try to write to netCDF using .to_netcdf(), I get an

IndexError: tuple index out of range

I can fix this by manually doing

d_['species'] = np.atleast_1d(d_['species'])
d_['category'] = np.atleast_1d(d_['category'])

before calling .to_netcdf().

I believe it would be good if xarray would do this check on its own and apply the coorection on-the-fly to allow saving to netCDF in this case as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions