-
Notifications
You must be signed in to change notification settings - Fork 267
netCDF4-python writes string (unicode) attributes as 1-d arrays, not scalars #448
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
Comments
Seems like when
I think you are right that this is due to how |
Should I open a bug report for the C library, then? |
Sure, wouldn't hurt. At the very least maybe we will found out why they chose to do it that way. |
This code writes a single string attribute to an HDF5 file using netCDF4:
Here's code do to the same thing with h5py:
As you can see from the results of
h5dump
, netCDF4-python is writing the attribute as a "simple dataspace" which corresponds to a multi-dimensional array of 1-element:https://www.hdfgroup.org/HDF5/doc/UG/UG_frame12Dataspaces.html
In fact, this is exactly what you get if you view the file created with netCDF4-python using h5py (to netCDF4-python and ncdump, they appear identical):
I believe netCDF4-python should be writing the attribute as a scalar, similarly to want it does if you write bytes (or a string on Python 2):
Given that netCDF4-python is simply using the netCDF-C library's
nc_put_att_string
function, this may very well be a bug upstream in the netCDF-C library.The text was updated successfully, but these errors were encountered: