8000 changed references & added whatsnew · pydata/xarray@05e8d72 · GitHub
[go: up one dir, main page]

Skip to content

Commit 05e8d72

Browse files
committed
changed references & added whatsnew
1 parent 514219e commit 05e8d72

File tree

10 files changed

+34
-30
lines changed

10 files changed

+34
-30
lines changed

doc/examples/multidimensional-coords.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function to specify the output coordinates of the group.
107107
lat_center = np.arange(1, 90, 2)
108108
# group according to those bins and take the mean
109109
Tair_lat_mean = (ds.Tair.groupby_bins('xc', lat_bins, labels=lat_center)
110-
.mean(xr.ALL_DIMS))
10000 110+
.mean(...))
111111
# plot the result
112112
@savefig xarray_multidimensional_coords_14_1.png width=5in
113113
Tair_lat_mean.plot();

doc/groupby.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ dimensions *other than* the provided one:
116116

117117
.. ipython:: python
118118
119-
ds.groupby('x').std(xr.ALL_DIMS)
119+
ds.groupby('x').std(...)
120120
121121
First and last
122122
~~~~~~~~~~~~~~
@@ -127,7 +127,7 @@ values for group along the grouped dimension:
127127

128128
.. ipython:: python
129129
130-
ds.groupby('letters').first(xr.ALL_DIMS)
130+
ds.groupby('letters').first(...)
131131
132132
By default, they skip missing values (control this with ``skipna``).
133133

@@ -142,7 +142,7 @@ coordinates. For example:
142142

143143
.. ipython:: python
144144
145-
alt = arr.groupby('letters').mean(xr.ALL_DIMS)
145+
alt = arr.groupby('letters').mean(...)
146146
alt
147147
ds.groupby('letters') - alt
148148
@@ -195,7 +195,7 @@ __ http://cfconventions.org/cf-conventions/v1.6.0/cf-conventions.html#_two_dimen
195195
'lat': (['ny','nx'], [[10,10],[20,20]] ),},
196196
dims=['ny','nx'])
197197
da
198-
da.groupby('lon').sum(xr.ALL_DIMS)
198+
da.groupby('lon').sum(...)
199199
da.groupby('lon').apply(lambda x: x - x.mean(), shortcut=False)
200200
201201
Because multidimensional groups have the ability to generate a very large
@@ -213,4 +213,4 @@ applying your function, and then unstacking the result:
213213
.. ipython:: python
214214
215215
stacked = da.stack(gridcell=['ny', 'nx'])
216-
stacked.groupby('gridcell').sum(xr.ALL_DIMS).unstack('gridcell')
216+
stacked.groupby('gridcell').sum(...).unstack('gridcell')

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ v0.14.1 (unreleased)
2020

2121
New Features
2222
~~~~~~~~~~~~
23+
- Changed `xr.ALL_DIMS` to equal python's `Ellipsis` (`...`), and changed internal usages to use
24+
`...` directly. As before, you can use this to instruct a `groupby` operation
25+
to reduce over all dimensions. While we have no plans to remove `xr.ALL_DIMS`, we suggest
26+
using `...`.
27+
By `Maximilian Roos <https://github.com/max-sixty>`_
2328
- Added integration tests against `pint <https://pint.readthedocs.io/>`_.
2429
(:pull:`3238`) by `Justus Magin <https://github.com/keewis>`_.
2530

xarray/core/dataset.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
)
4848
from .alignment import _broadcast_helper, _get_broadcast_dims_map_common_coords, align
4949
from .common import (
50-
ALL_DIMS,
5150
DataWithCoords,
5251
ImplementsDatasetReduce,
5352
_contains_datetime_like_objects,
@@ -4032,7 +4031,7 @@ def reduce(
40324031
Dataset with this object's DataArrays replaced with new DataArrays
40334032
of summarized data and the indicated dimension(s) removed.
40344033
"""
4035-
if dim is None or dim is ALL_DIMS:
4034+
if dim is None or dim is ...:
40364035
dims = set(self.dims)
40374036
elif isinstance(dim, str) or not isinstance(dim, Iterable):
40384037
dims = {dim}
@@ -4997,7 +4996,7 @@ def quantile(
49974996

49984997
if isinstance(dim, str):
49994998
dims = {dim}
5000-
elif dim is None or dim is ALL_DIMS:
4999+
elif dim in [None, ...]:
50015000
dims = set(self.dims)
50025001
else:
50035002
dims = set(dim)

xarray/core/groupby.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from . import dtypes, duck_array_ops, nputils, ops
99
from .arithmetic import SupportsArithmetic
10-
from .common import ALL_DIMS, ImplementsArrayReduce, ImplementsDatasetReduce
10+
from .common import ImplementsArrayReduce, ImplementsDatasetReduce
1111
from .concat import concat
1212
from .formatting import format_array_flat
1313
from .options import _get_keep_attrs
@@ -712,7 +712,7 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):
712712
q : float in range of [0,1] (or sequence of floats)
713713
Quantile to compute, which must be between 0 and 1
714714
inclusive.
715-
dim : xarray.ALL_DIMS (or `...`), str or sequence of str, optional
715+
dim : `...`, str or sequence of str, optional
716716
Dimension(s) over which to apply quantile.
717717
Defaults to the grouped dimension.
718718
interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
@@ -769,7 +769,7 @@ def reduce(
769769
Function which can be called in the form
770770
`func(x, axis=axis, **kwargs)` to return the result of collapsing
771771
an np.ndarray over an integer valued axis.
772-
dim : xarray.ALL_DIMS (or `...`), str or sequence of str, optional
772+
dim : `...`, str or sequence of str, optional
773773
Dimension(s) over which to apply `func`.
774774
axis : int or sequence of int, optional
775775
Axis(es) over which to apply `func`. Only one of the 'dimension'
@@ -794,9 +794,9 @@ def reduce(
794794
if keep_attrs is None:
795795
keep_attrs = _get_keep_attrs(default=False)
796796

797-
if dim is not ALL_DIMS and dim not in self.dims:
797+
if dim is not ... and dim not in self.dims:
798798
raise ValueError(
799-
"cannot reduce over dimension %r. expected either xarray.ALL_DIMS (or `...`) to reduce over all dimensions or one or more of %r."
799+
"cannot reduce over dimension %r. expected either `...` to reduce over all dimensions or one or more of %r."
800800
% (dim, self.dims)
801801
)
802802

@@ -867,7 +867,7 @@ def reduce(self, func, dim=None, keep_attrs=None, **kwargs):
867867
Function which can be called in the form
868868
`func(x, axis=axis, **kwargs)` to return the result of collapsing
869869
an np.ndarray over an integer valued axis.
870-
dim : xarray.ALL_DIMS (or `...`), str or sequence of str, optional
870+
dim : `...`, str or sequence of str, optional
871871
Dimension(s) over which to apply `func`.
872872
axis : int or sequence of int, optional
873873
Axis(es) over which to apply `func`. Only one of the 'dimension'
@@ -895,9 +895,9 @@ def reduce(self, func, dim=None, keep_attrs=None, **kwargs):
895895
def reduce_dataset(ds):
896896
return ds.reduce(func, dim, keep_attrs, **kwargs)
897897

898-
if dim is not ALL_DIMS and dim not in self.dims:
898+
if dim is not ... and dim not in self.dims:
899899
raise ValueError(
900-
"cannot reduce over dimension %r. expected either xarray.ALL_DIMS (or `...`) to reduce over all dimensions or one or more of %r."
900+
"cannot reduce over dimension %r. expected either `...` to reduce over all dimensions or one or more of %r."
901901
% (dim, self.dims)
902902
)
903903

xarray/core/variable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ def reduce(
14501450
Array with summarized data and the indicated dimension(s)
14511451
removed.
14521452
"""
1453-
if dim is common.ALL_DIMS:
1453+
if dim == ...:
14541454
dim = None
14551455
if dim is not None and axis is not None:
14561456
raise ValueError("cannot supply both 'axis' and 'dim' arguments")

xarray/tests/test_dask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ def test_groupby(self):
435435
u = self.eager_array
436436
v = self.lazy_array
437437

438-
expected = u.groupby("x").mean(xr.ALL_DIMS)
439-
actual = v.groupby("x").mean(xr.ALL_DIMS)
438+
expected = u.groupby("x").mean(...)
439+
actual = v.groupby("x").mean(...)
440440
self.assertLazyAndAllClose(expected, actual)
441441

442442
def test_groupby_first(self):

xarray/tests/test_groupby.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ def test_da_groupby_quantile():
147147
[("x", [1, 1, 1, 2, 2]), ("y", [0, 0, 1])],
148148
)
149149

150-
actual_x = array.groupby("x").quantile(0, dim=xr.ALL_DIMS)
150+
actual_x = array.groupby("x").quantile(0, dim=...)
151151
expected_x = xr.DataArray([1, 4], [("x", [1, 2])])
152152
assert_identical(expected_x, actual_x)
153153

154-
actual_y = array.groupby("y").quantile(0, dim=xr.ALL_DIMS)
154+
actual_y = array.groupby("y").quantile(0, dim=...)
155155
expected_y = xr.DataArray([1, 22], [("y", [0, 1])])
156156
assert_identical(expected_y, actual_y)
157157

@@ -177,7 +177,7 @@ def test_da_groupby_quantile():
177177
)
178178
g = foo.groupby(foo.time.dt.month)
179179

180-
actual = g.quantile(0, dim=xr.ALL_DIMS)
180+
actual = g.quantile(0, dim=...)
181181
expected = xr.DataArray(
182182
[
183183
0.0,

xarray/tests/test_plot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_convenient_facetgrid_4d(self):
417417

418418
def test_coord_with_interval(self):
419419
bins = [-1, 0, 1, 2]
420-
self.darray.groupby_bins("dim_0", bins).mean(xr.ALL_DIMS).plot()
420+
self.darray.groupby_bins("dim_0", bins).mean(...).plot()
421421

422422

423423
class TestPlot1D(PlotTestCase):
@@ -502,7 +502,7 @@ def test_step(self):
502502

503503
def test_coord_with_interval_step(self):
504504
bins = [-1, 0, 1, 2]
505-
self.darray.groupby_bins("dim_0", bins).mean(xr.ALL_DIMS).plot.step()
505+
self.darray.groupby_bins("dim_0", bins).mean(...).plot.step()
506506
assert len(plt.gca().lines[0].get_xdata()) == ((len(bins) - 1) * 2)
507507

508508

@@ -544,7 +544,7 @@ def test_plot_nans(self):
544544
def test_hist_coord_with_interval(self):
545545
(
546546
self.darray.groupby_bins("dim_0", [-1, 0, 1, 2])
547-
.mean(xr.ALL_DIMS)
547+
.mean(...)
548548
.plot.hist(range=(-1, 2))
549549
)
550550

xarray/tests/test_sparse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,8 @@ def test_dot(self):
756756
def test_groupby(self):
757757
x1 = self.ds_xr
758758
x2 = self.sp_xr
759-
m1 = x1.groupby("x").mean(xr.ALL_DIMS)
760-
m2 = x2.groupby("x").mean(xr.ALL_DIMS)
759+
m1 = x1.groupby("x").mean(...)
760+
m2 = x2.groupby("x").mean(...)
761761
assert isinstance(m2.data, sparse.SparseArray)
762762
assert np.allclose(m1.data, m2.data.todense())
763763

@@ -772,8 +772,8 @@ def test_groupby_first(self):
772772
def test_groupby_bins(self):
773773
x1 = self.ds_xr
774774
x2 = self.sp_xr
775-
m1 = x1.groupby_bins("x", bins=[0, 3, 7, 10]).sum(xr.ALL_DIMS)
776-
m2 = x2.groupby_bins("x", bins=[0, 3, 7, 10]).sum(xr.ALL_DIMS)
775+
m1 = x1.groupby_bins("x", bins=[0, 3, 7, 10]).sum(...)
776+
m2 = x2.groupby_bins("x", bins=[0, 3, 7, 10]).sum(...)
777777
assert isinstance(m2.data, sparse.SparseArray)
778778
assert np.allclose(m1.data, m2.data.todense())
779779

0 commit comments

Comments
 (0)
0