Consider the following gist where I receive the following error: TypeError: DataArray.name or Dataset key must be either a string or None for serialization to netCDF files.
I think that I run into a bug when DataArray.name is checked by check_name function. I think that k in the corresponding for loop actually represents DataArray not DataArray.name itself. Thus, I suggest something like this to fix it:
for k in dataset:
check_name(k.name)
@kuchaale - Thanks for the report. You are trying to save a list of DataArray objects using save_mfdataset, which does not currently support saving DataArrays to netCDF.
Changing your line:
foo = xr.DataArray(data, coords=[times, locs], dims=['time', 'space'])
foo.name = 'foo'
to
foo = xr.DataArray(data, coords=[times, locs], dims=['time', 'space']).to_dataset(name='foo')
corrects issue.
We could add a save_mfdataarray function or just handle the type conversion in save_mfdataset if that would be useful.
At a minimum, we should make sure that the objects passed to save_mfdataset are in fact datasets.
Most helpful comment
At a minimum, we should make sure that the objects passed to
save_mfdatasetare in fact datasets.