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

netCDF4 should error when assigning multi-dimensional arrays as attributes #841

Closed
shoyer opened this issue Aug 29, 2018 · 6 comments
Closed

Comments

@shoyer
Copy link
Contributor

shoyer commented Aug 29, 2018

Right now, they are silently flattened:

In [13]: import netCDF4

In [14]: with netCDF4.Dataset('testing.nc', 'w') as nc:
    ...:     nc.foo = ['multi', 'dimensional']
    ...:     nc.bar = [[1, 2], [3, 4]]
    ...:

In [15]: with netCDF4.Dataset('testing.nc') as nc:
    ...:     print(nc.foo)
    ...:     print(nc.bar)
    ...:
multidimensional
[1 2 3 4]

This was reported downstream by an xarray user: pydata/xarray#2251

@jswhit
Copy link
Collaborator

jswhit commented Aug 29, 2018

Agreed - this is a bug. Will submit a PR.

@jswhit
Copy link
Collaborator

jswhit commented Aug 29, 2018

I hope no one is depending on this behavior. Maybe we should issue a FutureWarning instead, and change it to ValueError in the next release.

@jswhit
Copy link
Collaborator

jswhit commented Aug 29, 2018

Note that nc.foo = ['multi', 'dimensional'] produces [u'multi', u'dimensional'] in master, so this PR will have no affect for this case. However nc.foo = [['multi'], ['dimensional']] will now raise a ValueError.

@shoyer
Copy link
Contributor Author

shoyer commented Aug 29, 2018 via email

@jswhit
Copy link
Collaborator

jswhit commented Aug 29, 2018

changed pull request #842 to FutureWarning

jswhit added a commit that referenced this issue Aug 30, 2018
raise ValueError when trying to set multi-dim array att (issue #841)
@jswhit
Copy link
Collaborator

jswhit commented Aug 30, 2018

pull request #824 merged. FutureWarning will change to ValueError in 1.4.3

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

No branches or pull requests

2 participants