home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 1863676757

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
1863676757 I_kwDOAMm_X85vFXNV 8105 Keep attributes across operations - "drop_conflicts" option? 47793072 open 0     1 2023-08-23T16:41:17Z 2023-08-31T03:54:01Z   NONE      

What is your issue?

The Problem When I perform simple operations (e.g., +, -, *, /) on DataArray objects, I expected compatible attributes to be maintained, and incompatible attributes to be removed. Even when playing with the available options for keep_attrs, this behavior does not occur. See also #4763 and #2582.

Here is an example showing what happens in each case:

python da1 = xr.DataArray(1, attrs=dict(unit_system='SI', a=7)) da2 = xr.DataArray(2, attrs=dict(unit_system='SI', a=8)) with xr.set_options(keep_attrs='default'): result = da1 + da2 result.attrs # {} with xr.set_options(keep_attrs=True): result = da1 + da2 result.attrs # {'unit_system': 'SI', 'a': 7}

Desired behavior: python result.attrs # {'unit_system': 'SI'} That is to say, I want attributes with conflicting values to be discarded, and all other attributes to be maintained.

Suggested Fix This is similar to the "drop_conflicts" option for merging attrs, from xarray.merge. I suggest that "drop_conflicts" be added as an option for keep_attrs. For example, I would like to be able to do: python with xr.set_options(keep_attrs="drop_conflicts"): result = da1 + da2 result.attrs # {'unit_system': 'SI'} If anyone else is able to add this option into the code, that would be amazing!

Or, if there is already a way to accomplish this behavior, I would appreciate any advice on how to do it.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.9.13 (main, Aug 25 2022, 18:29:29) [Clang 12.0.0 ] python-bits: 64 OS: Darwin OS-release: 21.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.10.6 libnetcdf: None xarray: 2023.8.0 pandas: 1.4.4 numpy: 1.21.5 scipy: 1.9.1 netCDF4: None pydap: None h5netcdf: None h5py: 3.7.0 Nio: None zarr: 2.13.6 cftime: None nc_time_axis: None PseudoNetCDF: None iris: None bottleneck: 1.3.5 dask: 2022.7.0 distributed: 2022.7.0 matplotlib: 3.5.2 cartopy: None seaborn: 0.11.2 numbagg: None fsspec: 2022.7.1 cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 63.4.1 pip: 22.2.2 conda: 22.9.0 pytest: 7.1.2 mypy: None IPython: 7.31.1 sphinx: 5.0.2
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/8105/reactions",
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

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