Skip to content

Wrong dimension referenced in boolean indexing with .loc #1436

Closed
@d-chambers

Description

@d-chambers

I am using Ubuntu 16, python 3.6, and xarary 0.9.5.

import numpy as np
import xarray as xr

# setup for a simple grid
DX = 50
X = np.arange(0, 2010, DX)
Y = np.arange(0, 2010, DX)
Z = np.arange(0, 2010, DX)
grid_shape = (len(X), len(Y), len(Z))

# Create data array
dims = 'X Y Z'.split()
coords = {'X': X, 'Y': Y, 'Z': Z}
dar = xr.DataArray(np.ones(grid_shape), dims=dims, coords=coords)

# slice the data array so that all Z values are greater than 1000
dar2 = dar.loc[dar.Z > 1000]
assert np.all(dar2.Z > 1000)  # fails becase dar is sliced along X, not Z

Since the object returned from dar.Z > 1000 is a data array with "Z" as the only dim I would expect this to slice the "Z" dim rather than X.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions