pydata / pydata/xarray

`where` grows new dimensions for unrelated variables

Open
#1,234 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

API design
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

In the example below, the dimensionality for data variable y grows from (b) to (b, a) after calling the dataset where method. This behaviour does not appear to be documented. Is it a bug?

    In [46]: ds = xarray.Dataset({"x": (("a", "b"), arange(25).reshape(5,5)+100), "y": ("b", arange(5)-100)}, {"a": arange(5), "b": arange(5)*2, "c": (("a",), list("ABCDE"))})
    
    In [47]: print(ds)
    <xarray.Dataset>
    Dimensions:  (a: 5, b: 5)
    Coordinates:
      * b        (b) int64 0 2 4 6 8
        c        (a) <U1 'A' 'B' 'C' 'D' 'E'
      * a        (a) int64 0 1 2 3 4
    Data variables:
        x        (a, b) int64 100 101 102 103 104 105 106 107 108 109 110 111 ...
        y        (b) int64 -100 -99 -98 -97 -96
    
    In [69]: ds.where((ds.c>='A') & (ds.c<='C'))
    Out[69]: 
    <xarray.Dataset>
    Dimensions:  (a: 5, b: 5)
    Coordinates:
      * b        (b) int64 0 2 4 6 8
        c        (a) <U1 'A' 'B' 'C' 'D' 'E'
      * a        (a) int64 0 1 2 3 4
    Data variables:
        x        (a, b) float64 100.0 101.0 102.0 103.0 104.0 105.0 106.0 107.0 ...
        y        (b, a) float64 -100.0 -100.0 -100.0 nan nan -99.0 -99.0 -99.0 ...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the documented Dataset.where example with xarray, checking how the data variable y changes from (b) to (b, a). Read the Dataset.where entry point and existing tests for where behavior, if available. Done means determining whether the dimensionality change is intended and adding or updating coverage and documentation accordingly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.