home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 636029447

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
636029447 MDU6SXNzdWU2MzYwMjk0NDc= 4136 xarray.where changes dimension order 59089956 closed 0     1 2020-06-10T08:06:16Z 2021-07-04T03:12:36Z 2021-07-04T03:12:36Z NONE      

Using xarray.where on a DataArray, changes the order of dimensions, putting the dimension, which was used in the condition in the first place.

This behavior can easily be reproduced with the code examples from xarray.where

MCVE Code Sample

```python import xarray as xr import numpy as np

y = xr.DataArray( 0.1 * np.arange(9).reshape(3, 3), dims=["lat", "lon"], coords={"lat": np.arange(3), "lon": 10 + np.arange(3)}, name="sst", )

z = xr.where(y.lon < 1, y, -1) ```

Expected Output

```

z <xarray.DataArray (lat: 3, lon: 3)> array([[-1., -1., -1.], [-1., -1., -1.], [-1., -1., -1.]]) Coordinates: * lon (lon) int64 10 11 12 * lat (lat) int64 0 1 2 ```

Actual Output

```

z <xarray.DataArray (lon: 3, lat: 3)> array([[-1., -1., -1.], [-1., -1., -1.], [-1., -1., -1.]]) Coordinates: * lon (lon) int64 10 11 12 * lat (lat) int64 0 1 2 ```

Problem Description

I believe this is problematic behavior, since xr.transpose creates only a view to the reordered array but does not permanently reorder the dimensions again.

Versions

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 22:45:16) [Clang 9.0.1 ] python-bits: 64 OS: Darwin OS-release: 19.4.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: None LOCALE: None.UTF-8 libhdf5: None libnetcdf: None xarray: 0.15.1 pandas: 1.0.3 numpy: 1.18.4 scipy: 1.3.3 netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.1.3 cartopy: None seaborn: None numbagg: None setuptools: 46.3.0.post20200513 pip: 20.1 conda: None pytest: 5.3.5 IPython: 7.14.0 sphinx: 3.0.3
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4136/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

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