-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
to_netcdf on Python 3: "string" qualifier on attributes #681
Comments
I had that happening with python2 as well - just for netcdf4 files though, because of the new string type I guess.. when writing as netcdf4-classic that string output was not shown. |
Yes, this is probably related to the netCDF4-python change discussed here: Unidata/netcdf4-python#388 Unfortunately, lots of older netCDF programs don't know how to interpret the netCDF4 "string" dtype -- and to be honest, even the netCDF-C library doesn't always properly save such data as Unicode yet, though that should be fixed in the next release (4.4.0 -- see Unidata/netcdf-c#127 for more details). So an alternative choice would be to attempt to always encode unicode (str on Python 3) attributes as ASCII when saving with netCDF4, e.g., def maybe_encode(string, encoding='ascii'):
try:
return string.encode(encoding)
except UnicodeEncodeError:
return string |
Exactly what I have done in the past. Does this seem like something we should change/fix? |
Yes, I would support this change. On Thu, Dec 17, 2015 at 10:43 AM, Joe Hamman [email protected]
|
This has been fixed upstream: Unidata/netcdf4-python#533 |
Is this still possibly an issue? |
@byersiiasa What version of netCDF4-Python are you using? This was fixed in netCDF4-Python v1.2.3. |
Turns out to be 1.2.2!. I am using the Anaconda installation and for some reason it is not updating to the latest version. |
I've had a number of people ask me about this and I think we can figure out a way to fix this. In python3, variabile attributes in files written with
Dataset.to_netcdf
end up with the "string" type qualifier shown below. This causes all sorts of problems with other netcdf programs. Is this related to Unidata/netcdf4-python#485?cc @lizaclark
The text was updated successfully, but these errors were encountered: