issues: 1414669747
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1414669747 | I_kwDOAMm_X85UUiWz | 7186 | netCDF4: support byte strings as attribute values | 64479100 | open | 0 | 2 | 2022-10-19T09:58:04Z | 2023-01-17T18:30:20Z | NONE | What is your issue?When I have a string attribute with special characters like '°' or German Umlauts (Ä, Ü, etc) it will get written to file as type NC_STRING. Other string attributes not containing any special characters will be saved as NC_CHAR. This leads to problems when I subsequently want to open this file with NetCDF-Fortran, because it does not fully support NC_STRING. So my question is: Is there a way to force xarray to write the string attribute as NC_CHAR? Example ```python import numpy as np import xarray as xr data = np.ones([12, 10])
ds = xr.Dataset({"data": (["x", "y"], data)}, coords={"x": np.arange(12), "y": np.arange(10)})
ds["x"].attrs["first_str"] = "foo"
ds["x"].attrs["second_str"] = "bar°"
ds["x"].attrs["third_str"] = "hää"
ds.to_netcdf("testds.nc")
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/7186/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |