issues: 1069449519
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1069449519 | I_kwDOAMm_X84_voEv | 6038 | DataArray.to_dataset(dim=...) does not preserve attributes | 8169721 | open | 0 | 0 | 2021-12-02T11:41:05Z | 2021-12-09T14:38:04Z | NONE | What happened:
When calling What you expected to happen: Attributes are copied to the variables. Minimal Complete Verifiable Example: ```python import numpy as np import xarray as xr this setting does not change the behaviourxr.set_options(keep_attrs=True) data = np.arange(234, dtype="uint16").reshape((2,3,4))
coords = [("band", ["1", "2"]), ("y", np.arange(3)), ("x", np.arange(4))]
da = xr.DataArray(data, coords=coords, attrs=dict(myattr=9999))
da
```
```python the attribute is always copied to the Dataset regardless of the promote_attrs valueds_split = da.to_dataset("band", promote_attrs=False)
ds_split
```
Anything else we need to know?:
If I avoid the splitting, the attribute is only in the This reproduces the expected behaviour:
Environment: Output of <tt>xr.show_versions()</tt>INSTALLED VERSIONS ------------------ commit: None python: 3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 21:59:51) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 4.15.0-111-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: None libnetcdf: None xarray: 0.20.1 pandas: 1.3.4 numpy: 1.21.4 scipy: 1.7.3 netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: 1.2.10 cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: None cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None setuptools: 59.4.0 pip: 21.3.1 conda: None pytest: None IPython: 7.30.0 sphinx: None |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/6038/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |