home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 784484810

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
784484810 MDU6SXNzdWU3ODQ0ODQ4MTA= 4798 attributes that are lists of strings with a single member don't survive a round-trip 7226087 open 0     7 2021-01-12T18:34:26Z 2023-09-16T09:52:10Z   NONE      

What happened:

If I create a Dataset with an attr that is a list of strings with only a single member, write it to netcdf and open it again, the attr is a single string instead of a list of strings.

What you expected to happen:

Writing the Dataset to netcdf and opening it should not change the attrs.

Minimal Complete Verifiable Example:

```python import xarray as xr

ds = xr.Dataset(attrs={"foo": ["bar"]},)

ds.to_netcdf("ds.nc", engine="netcdf4") rd = xr.open_dataset("ds.nc", engine="netcdf4")

assert ds.attrs["foo"] == rd.attrs["foo"] ```

Anything else we need to know?:

This was implemented in PR2045, including the test test_setncattr_string. However, there assert_array_equal is used to compare the attrs after a roundtrip (line 1454 ), which unfortunately compares element-wise if one of the elements is a scalar. Changing the test like this: diff - assert_array_equal(one_element_list_of_strings, totest.attrs["bar"]) + assert one_element_list_of_strings == totest.attrs["bar"] corrects it (the test then fails currently).

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: f52a95cbe694336fe47bc5a42c713bee8ad74d64 python: 3.8.6 (default, Sep 25 2020, 09:36:53) [GCC 10.2.0] python-bits: 64 OS: Linux OS-release: 5.8.0-36-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.12.0 libnetcdf: 4.7.4 xarray: 0.16.3.dev75+gf52a95cb pandas: 1.2.0 numpy: 1.19.5 scipy: None netCDF4: 1.5.5.1 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.3.0 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2020.12.0 distributed: 2020.12.0 matplotlib: None cartopy: None seaborn: None numbagg: None pint: None setuptools: 51.1.2 pip: 20.3.3 conda: None pytest: 6.2.1 IPython: None sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4798/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 3 rows from issues_id in issues_labels
  • 6 rows from issue in issue_comments
Powered by Datasette · Queries took 0.515ms · About: xarray-datasette