home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 583080947

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
583080947 MDU6SXNzdWU1ODMwODA5NDc= 3865 `merge` drops attributes 3958036 closed 0     1 2020-03-17T15:06:18Z 2020-03-24T20:40:18Z 2020-03-24T20:40:18Z CONTRIBUTOR      

xarray.merge() drops the attrs of Datasets being merged. They should be kept, at least if they are compatible

MCVE Code Sample

```python

Your code here

import xarray as xr

ds1 = xr.Dataset() ds1.attrs['a'] = 42 ds2 = xr.Dataset() ds2.attrs['a'] = 42

merged = xr.merge([ds1, ds2])

print(merged) the result is <xarray.Dataset> Dimensions: () Data variables: empty ```

Expected Output

<xarray.Dataset> Dimensions: () Data variables: *empty* Attributes: a: 42

Problem Description

The current behaviour means I have to check and copy attrs to the result of merge by hand, even if the attrs of the inputs were identical or not conflicting.

I'm happy to attempt a PR to fix this. Proposal (following pattern of compat arguments): * add a combine_attrs argument to xarray.merge * combine_attrs = 'drop' do not copy attrs (current behaviour) * combine_attrs = 'identical' if attrs of all inputs are identical (using dict_equiv) then copy the attrs to the result, otherwise raise an exception * combine_attrs = 'no_conflicts' merge the attrs of all inputs, as long as any keys shared by more than one input have the same value (if not raise an exception) [I propose this is the default behaviour] * override copy the attrs from the first input, to the result

This proposal should also allow combine_by_coords, etc. to preserve attributes. These should probably also take a combine_attrs argument, which would be passed through to merge.

Versions

Current master of pydata/xarray on 17/3/2020

Output of `xr.show_versions()` INSTALLED VERSIONS ------------------ commit: None python: 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0] python-bits: 64 OS: Linux OS-release: 5.3.0-40-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 libhdf5: 1.10.2 libnetcdf: 4.6.3 xarray: 0.15.0 pandas: 1.0.2 numpy: 1.18.1 scipy: 1.3.0 netCDF4: 1.5.1.2 pydap: None h5netcdf: None h5py: 2.9.0 Nio: None zarr: None cftime: 1.0.3.4 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.12.0 distributed: None matplotlib: 3.1.1 cartopy: None seaborn: None numbagg: None setuptools: 45.2.0 pip: 9.0.1 conda: None pytest: 4.4.1 IPython: 7.8.0 sphinx: 1.8.3
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3865/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 0.587ms · About: xarray-datasette