Skip to content

Commit 3391fec

Browse files
raybellwavesRay Bell
and
Ray Bell
authored
DOC: add query examples (#5249)
* DOC: add query examples * rm whitespace Co-authored-by: Ray Bell <ray.bell@dtn.com>
1 parent 73d7d6e commit 3391fec

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

xarray/core/dataarray.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4452,6 +4452,17 @@ def query(
44524452
Dataset.query
44534453
pandas.eval
44544454
4455+
Examples
4456+
--------
4457+
>>> da = xr.DataArray(np.arange(0, 5, 1), dims="x", name="a")
4458+
>>> da
4459+
<xarray.DataArray 'a' (x: 5)>
4460+
array([0, 1, 2, 3, 4])
4461+
Dimensions without coordinates: x
4462+
>>> da.query(x="a > 2")
4463+
<xarray.DataArray 'a' (x: 2)>
4464+
array([3, 4])
4465+
Dimensions without coordinates: x
44554466
"""
44564467

44574468
ds = self._to_dataset_whole(shallow_copy=True)

xarray/core/dataset.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7235,6 +7235,25 @@ def query(
72357235
Dataset.isel
72367236
pandas.eval
72377237
7238+
Examples
7239+
--------
7240+
>>> a = np.arange(0, 5, 1)
7241+
>>> b = np.linspace(0, 1, 5)
7242+
>>> ds = xr.Dataset({"a": ("x", a), "b": ("x", b)})
7243+
>>> ds
7244+
<xarray.Dataset>
7245+
Dimensions: (x: 5)
7246+
Dimensions without coordinates: x
7247+
Data variables:
7248+
a (x) int64 0 1 2 3 4
7249+
b (x) float64 0.0 0.25 0.5 0.75 1.0
7250+
>>> ds.query(x="a > 2")
7251+
<xarray.Dataset>
7252+
Dimensions: (x: 2)
7253+
Dimensions without coordinates: x
7254+
Data variables:
7255+
a (x) int64 3 4
7256+
b (x) float64 0.75 1.0
72387257
"""
72397258

72407259
# allow queries to be given either as a dict or as kwargs

0 commit comments

Comments
 (0)