home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 2007887740

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
2007887740 I_kwDOAMm_X853re98 8480 Using `where` without `keep_attrs=True` removes attrs stored in coordinates on the inputs 20397548 closed 0     3 2023-11-23T10:16:04Z 2023-11-24T08:24:35Z 2023-11-24T08:24:35Z CONTRIBUTOR      

What happened?

Sometimes I store info about coordinates in the attributes on the coordinate. It's useful for stuff like units or resolutions. I noticed that these attributes can go missing from DataArrays that are used as the input to xr.where, which is a somewhat unexpected side-effect.

What did you expect to happen?

The input DataArray is left unmodified by xr.where.

Minimal Complete Verifiable Example

```Python import xarray as xr import numpy as np

values = xr.DataArray(np.linspace(0, 2), dims='x') values = values.assign_coords(x=values.x.assign_attrs(attr=10)) print('attr' in values.x.attrs) # True nonzero = values != 0 print('attr' in values.x.attrs) # True xr.where(nonzero, values, np.nan, keep_attrs=False) print('attr' in values.x.attrs) # False ```

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.
  • [X] Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.11.0 | packaged by conda-forge | (main, Oct 25 2022, 06:09:06) [MSC v.1929 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 142 Stepping 12, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: ('Swedish_Sweden', '1252') libhdf5: None libnetcdf: None xarray: 2023.11.0 pandas: 1.5.1 numpy: 1.23.4 scipy: 1.9.3 netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: 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 flox: None numpy_groupies: None setuptools: 65.5.1 pip: 22.3.1 conda: None pytest: None mypy: None IPython: 8.6.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/8480/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

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