Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: DataArray.name or Dataset key must be either a string or None for serialization to netCDF files #1555

Closed
kuchaale opened this issue Sep 6, 2017 · 2 comments

Comments

@kuchaale
Copy link

kuchaale commented Sep 6, 2017

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)

@jhamman
Copy link
Member

jhamman commented Sep 6, 2017

@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.

@jhamman
Copy link
Member

jhamman commented Sep 6, 2017

At a minimum, we should make sure that the objects passed to save_mfdataset are in fact datasets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants