Skip to content

Commit 17d18ce

Browse files
TomNicholasshoyer
authored andcommitted
Rename combine functions (pydata#3043)
* Renamed combine functions in code * Renamed combine functions in docs * pep8 fixes * Fixed mistake in docstring * Removed trailing whitespace in error messages
1 parent 8c73852 commit 17d18ce

File tree

10 files changed

+162
-158
lines changed

10 files changed

+162
-158
lines changed

doc/api.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Top-level functions
2020
concat
2121
merge
2222
auto_combine
23-
combine_auto
24-
combine_manual
23+
combine_by_coords
24+
combine_nested
2525
where
2626
set_options
2727
full_like

doc/combining.rst

+14-14
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,23 @@ Combining along multiple dimensions
247247
.. note::
248248

249249
There are currently three combining functions with similar names:
250-
:py:func:`~xarray.auto_combine`, :py:func:`~xarray.combine_auto`, and
251-
:py:func:`~xarray.combine_manual`. This is because
250+
:py:func:`~xarray.auto_combine`, :py:func:`~xarray.combine_by_coords`, and
251+
:py:func:`~xarray.combine_nested`. This is because
252252
``auto_combine`` is in the process of being deprecated in favour of the other
253253
two functions, which are more general. If your code currently relies on
254254
``auto_combine``, then you will be able to get similar functionality by using
255-
``combine_manual``.
255+
``combine_nested``.
256256

257257
For combining many objects along multiple dimensions xarray provides
258-
:py:func:`~xarray.combine_manual`` and :py:func:`~xarray.combine_auto`. These
258+
:py:func:`~xarray.combine_nested`` and :py:func:`~xarray.combine_by_coords`. These
259259
functions use a combination of ``concat`` and ``merge`` across different
260260
variables to combine many objects into one.
261261

262-
:py:func:`~xarray.combine_manual`` requires specifying the order in which the
263-
objects should be combined, while :py:func:`~xarray.combine_auto` attempts to
262+
:py:func:`~xarray.combine_nested`` requires specifying the order in which the
263+
objects should be combined, while :py:func:`~xarray.combine_by_coords` attempts to
264264
infer this ordering automatically from the coordinates in the data.
265265

266-
:py:func:`~xarray.combine_manual` is useful when you know the spatial
266+
:py:func:`~xarray.combine_nested` is useful when you know the spatial
267267
relationship between each object in advance. The datasets must be provided in
268268
the form of a nested list, which specifies their relative position and
269269
ordering. A common task is collecting data from a parallelized simulation where
@@ -276,9 +276,9 @@ datasets into a doubly-nested list, e.g:
276276
arr = xr.DataArray(name='temperature', data=np.random.randint(5, size=(2, 2)), dims=['x', 'y'])
277277
arr
278278
ds_grid = [[arr, arr], [arr, arr]]
279-
xr.combine_manual(ds_grid, concat_dim=['x', 'y'])
279+
xr.combine_nested(ds_grid, concat_dim=['x', 'y'])
280280
281-
:py:func:`~xarray.combine_manual` can also be used to explicitly merge datasets
281+
:py:func:`~xarray.combine_nested` can also be used to explicitly merge datasets
282282
with different variables. For example if we have 4 datasets, which are divided
283283
along two times, and contain two different variables, we can pass ``None``
284284
to ``'concat_dim'`` to specify the dimension of the nested list over which
@@ -289,25 +289,25 @@ we wish to use ``merge`` instead of ``concat``:
289289
temp = xr.DataArray(name='temperature', data=np.random.randn(2), dims=['t'])
290290
precip = xr.DataArray(name='precipitation', data=np.random.randn(2), dims=['t'])
291291
ds_grid = [[temp, precip], [temp, precip]]
292-
xr.combine_manual(ds_grid, concat_dim=['t', None])
292+
xr.combine_nested(ds_grid, concat_dim=['t', None])
293293
294-
:py:func:`~xarray.combine_auto` is for combining objects which have dimension
294+
:py:func:`~xarray.combine_by_coords` is for combining objects which have dimension
295295
coordinates which specify their relationship to and order relative to one
296296
another, for example a linearly-increasing 'time' dimension coordinate.
297297

298298
Here we combine two datasets using their common dimension coordinates. Notice
299299
they are concatenated in order based on the values in their dimension
300-
coordinates, not on their position in the list passed to ``combine_auto``.
300+
coordinates, not on their position in the list passed to ``combine_by_coords``.
301301

302302
.. ipython:: python
303303
:okwarning:
304304
305305
x1 = xr.DataArray(name='foo', data=np.random.randn(3), coords=[('x', [0, 1, 2])])
306306
x2 = xr.DataArray(name='foo', data=np.random.randn(3), coords=[('x', [3, 4, 5])])
307-
xr.combine_auto([x2, x1])
307+
xr.combine_by_coords([x2, x1])
308308
309309
These functions can be used by :py:func:`~xarray.open_mfdataset` to open many
310310
files as one dataset. The particular function used is specified by setting the
311-
argument ``'combine'`` to ``'auto'`` or ``'manual'``. This is useful for
311+
argument ``'combine'`` to ``'by_coords'`` or ``'nested'``. This is useful for
312312
situations where your data is split across many files in multiple locations,
313313
which have some known relationship between one another.

doc/computation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object:
160160
161161
Aggregation results are assigned the coordinate at the end of each window by
162162
default, but can be centered by passing ``center=True`` when constructing the
163-
``Rolling`` object:
163+
``Rolling`` object:
164164

165165
.. ipython:: python
166166

doc/io.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ Combining multiple files
767767
NetCDF files are often encountered in collections, e.g., with different files
768768
corresponding to different model runs. xarray can straightforwardly combine such
769769
files into a single Dataset by making use of :py:func:`~xarray.concat`,
770-
:py:func:`~xarray.merge`, :py:func:`~xarray.combine_manual` and
771-
:py:func:`~xarray.combine_auto`. For details on the difference between these
770+
:py:func:`~xarray.merge`, :py:func:`~xarray.combine_nested` and
771+
:py:func:`~xarray.combine_by_coords`. For details on the difference between these
772772
functions see :ref:`combining data`.
773773

774774
.. note::

doc/whats-new.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ Enhancements
6060
Datasets can now be combined along any number of dimensions,
6161
instead of just a one-dimensional list of datasets.
6262

63-
The new ``combine_manual`` will accept the datasets as a a nested
63+
The new ``combine_nested`` will accept the datasets as a a nested
6464
list-of-lists, and combine by applying a series of concat and merge
65-
operations. The new ``combine_auto`` will instead use the dimension
65+
operations. The new ``combine_by_coords`` will instead use the dimension
6666
coordinates of the datasets to order them.
6767

68-
``open_mfdataset`` can use either ``combine_manual`` or ``combine_auto`` to
68+
``open_mfdataset`` can use either ``combine_nested`` or ``combine_by_coords`` to
6969
combine datasets along multiple dimensions, by specifying the argument
70-
`combine='manual'` or `combine='auto'`.
70+
`combine='nested'` or `combine='by_coords'`.
7171

7272
This means that the original function ``auto_combine`` is being deprecated.
73-
To avoid FutureWarnings switch to using `combine_manual` or `combine_auto`,
73+
To avoid FutureWarnings switch to using `combine_nested` or `combine_by_coords`,
7474
(or set the `combine` argument in `open_mfdataset`). (:issue:`2159`)
7575
By `Tom Nicholas <http://github.com/TomNicholas>`_.
7676
- Better warning message when supplying invalid objects to ``xr.merge``

xarray/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .core.alignment import align, broadcast, broadcast_arrays
99
from .core.common import full_like, zeros_like, ones_like
1010
from .core.concat import concat
11-
from .core.combine import combine_auto, combine_manual, auto_combine
11+
from .core.combine import combine_by_coords, combine_nested, auto_combine
1212
from .core.computation import apply_ufunc, dot, where
1313
from .core.extensions import (register_dataarray_accessor,
1414
register_dataset_accessor)

xarray/backends/api.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .. import Dataset, DataArray, backends, conventions
1111
from ..core import indexing
1212
from .. import auto_combine
13-
from ..core.combine import (combine_auto, _manual_combine,
13+
from ..core.combine import (combine_by_coords, _nested_combine,
1414
_infer_concat_order_from_positions)
1515
from ..core.utils import close_on_error, is_grib_path, is_remote_uri
1616
from .common import ArrayWriter
@@ -599,15 +599,16 @@ def open_mfdataset(paths, chunks=None, concat_dim='_not_supplied',
599599
**kwargs):
600600
"""Open multiple files as a single dataset.
601601
602-
If combine='auto' then the function `combine_auto` is used to combine the
603-
datasets into one before returning the result, and if combine='manual' then
604-
`combine_manual` is used. The filepaths must be structured according to
605-
which combining function is used, the details of which are given in the
606-
documentation for ``combine_auto`` and ``combine_manual``.
607-
By default the old (now deprecated) ``auto_combine`` will be used, please
608-
specify either ``combine='auto'`` or ``combine='manual'`` in future.
609-
Requires dask to be installed. See documentation for details on dask [1].
610-
Attributes from the first dataset file are used for the combined dataset.
602+
If combine='by_coords' then the function ``combine_by_coords`` is used to
603+
combine the datasets into one before returning the result, and if
604+
combine='nested' then ``combine_nested`` is used. The filepaths must be
605+
structured according to which combining function is used, the details of
606+
which are given in the documentation for ``combine_by_coords`` and
607+
``combine_nested``. By default the old (now deprecated) ``auto_combine``
608+
will be used, please specify either ``combine='by_coords'`` or
609+
``combine='nested'`` in future. Requires dask to be installed. See
610+
documentation for details on dask [1]. Attributes from the first dataset
611+
file are used for the combined dataset.
611612
612613
Parameters
613614
----------
@@ -631,11 +632,11 @@ def open_mfdataset(paths, chunks=None, concat_dim='_not_supplied',
631632
if you want to stack a collection of 2D arrays along a third dimension.
632633
Set ``concat_dim=[..., None, ...]`` explicitly to
633634
disable concatenation along a particular dimension.
634-
combine : {'auto', 'manual'}, optional
635-
Whether ``xarray.auto_combine`` or ``xarray.manual_combine`` is used to
636-
combine all the data. If this argument is not provided,
635+
combine : {'by_coords', 'nested'}, optional
636+
Whether ``xarray.combine_by_coords`` or ``xarray.combine_nested`` is
637+
used to combine all the data. If this argument is not provided,
637638
`xarray.auto_combine` is used, but in the future this behavior will
638-
switch to use `xarray.combine_auto`.
639+
switch to use `xarray.combine_by_coords` by default.
639640
compat : {'identical', 'equals', 'broadcast_equals',
640641
'no_conflicts'}, optional
641642
String indicating how to compare variables of the same name for
@@ -706,8 +707,8 @@ def open_mfdataset(paths, chunks=None, concat_dim='_not_supplied',
706707
707708
See Also
708709
--------
709-
combine_auto
710-
combine_manual
710+
combine_by_coords
711+
combine_nested
711712
auto_combine
712713
open_dataset
713714
@@ -730,13 +731,13 @@ def open_mfdataset(paths, chunks=None, concat_dim='_not_supplied',
730731
if not paths:
731732
raise IOError('no files to open')
732733

733-
# If combine='auto' then this is unnecessary, but quick.
734-
# If combine='manual' then this creates a flat list which is easier to
734+
# If combine='by_coords' then this is unnecessary, but quick.
735+
# If combine='nested' then this creates a flat list which is easier to
735736
# iterate over, while saving the originally-supplied structure as "ids"
736-
if combine == 'manual':
737+
if combine == 'nested':
737738
if str(concat_dim) == '_not_supplied':
738739
raise ValueError("Must supply concat_dim when using "
739-
"combine='manual'")
740+
"combine='nested'")
740741
else:
741742
if isinstance(concat_dim, (str, DataArray)) or concat_dim is None:
742743
concat_dim = [concat_dim]
@@ -776,17 +777,17 @@ def open_mfdataset(paths, chunks=None, concat_dim='_not_supplied',
776777
combined = auto_combine(datasets, concat_dim=concat_dim,
777778
compat=compat, data_vars=data_vars,
778779
coords=coords)
779-
elif combine == 'manual':
780+
elif combine == 'nested':
780781
# Combined nested list by successive concat and merge operations
781782
# along each dimension, using structure given by "ids"
782-
combined = _manual_combine(datasets, concat_dims=concat_dim,
783+
combined = _nested_combine(datasets, concat_dims=concat_dim,
783784
compat=compat, data_vars=data_vars,
784785
coords=coords, ids=ids)
785-
elif combine == 'auto':
786+
elif combine == 'by_coords':
786787
# Redo ordering from coordinates, ignoring how they were ordered
787788
# previously
788-
combined = combine_auto(datasets, compat=compat,
789-
data_vars=data_vars, coords=coords)
789+
combined = combine_by_coords(datasets, compat=compat,
790+
data_vars=data_vars, coords=coords)
790791
else:
791792
raise ValueError("{} is an invalid option for the keyword argument"
792793
" ``combine``".format(combine))

xarray/core/combine.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ def _combine_1d(datasets, concat_dim, compat='no_conflicts', data_vars='all',
216216
except ValueError as err:
217217
if "encountered unexpected variable" in str(err):
218218
raise ValueError("These objects cannot be combined using only "
219-
"xarray.combine_manual, instead either use "
220-
"xarray.combine_auto, or do it manually "
219+
"xarray.combine_nested, instead either use "
220+
"xarray.combine_by_coords, or do it manually "
221221
"with xarray.concat, xarray.merge and "
222222
"xarray.align")
223223
else:
@@ -233,7 +233,7 @@ def _new_tile_id(single_id_ds_pair):
233233
return tile_id[1:]
234234

235235

236-
def _manual_combine(datasets, concat_dims, compat, data_vars, coords, ids,
236+
def _nested_combine(datasets, concat_dims, compat, data_vars, coords, ids,
237237
fill_value=dtypes.NA):
238238

239239
if len(datasets) == 0:
@@ -259,7 +259,7 @@ def _manual_combine(datasets, concat_dims, compat, data_vars, coords, ids,
259259
return combined
260260

261261

262-
def combine_manual(datasets, concat_dim, compat='no_conflicts',
262+
def combine_nested(datasets, concat_dim, compat='no_conflicts',
263263
data_vars='all', coords='different', fill_value=dtypes.NA):
264264
"""
265265
Explicitly combine an N-dimensional grid of datasets into one by using a
@@ -335,7 +335,7 @@ def combine_manual(datasets, concat_dim, compat='no_conflicts',
335335
precipitation (x, y) float64 5.904 2.453 3.404 ...
336336
337337
>>> ds_grid = [[x1y1, x1y2], [x2y1, x2y2]]
338-
>>> combined = xr.combine_manual(ds_grid, concat_dim=['x', 'y'])
338+
>>> combined = xr.combine_nested(ds_grid, concat_dim=['x', 'y'])
339339
<xarray.Dataset>
340340
Dimensions: (x: 4, y: 4)
341341
Dimensions without coordinates: x, y
@@ -364,7 +364,7 @@ def combine_manual(datasets, concat_dim, compat='no_conflicts',
364364
precipitation (t) float64 5.904 2.453 3.404 ...
365365
366366
>>> ds_grid = [[t1temp, t1precip], [t2temp, t2precip]]
367-
>>> combined = xr.combine_manual(ds_grid, concat_dim=['t', None])
367+
>>> combined = xr.combine_nested(ds_grid, concat_dim=['t', None])
368368
<xarray.Dataset>
369369
Dimensions: (t: 10)
370370
Dimensions without coordinates: t
@@ -382,7 +382,7 @@ def combine_manual(datasets, concat_dim, compat='no_conflicts',
382382
concat_dim = [concat_dim]
383383

384384
# The IDs argument tells _manual_combine that datasets aren't yet sorted
385-
return _manual_combine(datasets, concat_dims=concat_dim, compat=compat,
385+
return _nested_combine(datasets, concat_dims=concat_dim, compat=compat,
386386
data_vars=data_vars, coords=coords, ids=False,
387387
fill_value=fill_value)
388388

@@ -391,8 +391,8 @@ def vars_as_keys(ds):
391391
return tuple(sorted(ds))
392392

393393

394-
def combine_auto(datasets, compat='no_conflicts', data_vars='all',
395-
coords='different', fill_value=dtypes.NA):
394+
def combine_by_coords(datasets, compat='no_conflicts', data_vars='all',
395+
coords='different', fill_value=dtypes.NA):
396396
"""
397397
Attempt to auto-magically combine the given datasets into one by using
398398
dimension coordinates.
@@ -449,14 +449,14 @@ def combine_auto(datasets, compat='no_conflicts', data_vars='all',
449449
--------
450450
concat
451451
merge
452-
combine_manual
452+
combine_nested
453453
454454
Examples
455455
--------
456456
457457
Combining two datasets using their common dimension coordinates. Notice
458458
they are concatenated based on the values in their dimension coordinates,
459-
not on their position in the list passed to `combine_auto`.
459+
not on their position in the list passed to `combine_by_coords`.
460460
461461
>>> x1
462462
<xarray.Dataset>
@@ -474,7 +474,7 @@ def combine_auto(datasets, compat='no_conflicts', data_vars='all',
474474
Data variables:
475475
temperature (x) float64 6.97 8.13 7.42 ...
476476
477-
>>> combined = xr.combine_auto([x2, x1])
477+
>>> combined = xr.combine_by_coords([x2, x1])
478478
<xarray.Dataset>
479479
Dimensions: (x: 6)
480480
Coords:
@@ -528,8 +528,8 @@ def auto_combine(datasets, concat_dim='_not_supplied', compat='no_conflicts',
528528
"""
529529
Attempt to auto-magically combine the given datasets into one.
530530
531-
This entire function is deprecated in favour of ``combine_manual`` and
532-
``combine_auto``.
531+
This entire function is deprecated in favour of ``combine_nested`` and
532+
``combine_by_coords``.
533533
534534
This method attempts to combine a list of datasets into a single entity by
535535
inspecting metadata and using a combination of concat and merge.
@@ -593,34 +593,35 @@ def auto_combine(datasets, concat_dim='_not_supplied', compat='no_conflicts',
593593
message = dedent("""\
594594
Also `open_mfdataset` will no longer accept a `concat_dim` argument.
595595
To get equivalent behaviour from now on please use the new
596-
`combine_manual` function instead (or the `combine='manual'` option to
596+
`combine_nested` function instead (or the `combine='nested'` option to
597597
`open_mfdataset`).""")
598598

599599
if _dimension_coords_exist(datasets):
600600
message += dedent("""\
601601
The datasets supplied have global dimension coordinates. You may want
602-
to use the new `combine_auto` function (or the `combine='auto'` option
603-
to `open_mfdataset` to order the datasets before concatenation.
604-
Alternatively, to continue concatenating based on the order the
605-
datasets are supplied in in future, please use the new `combine_manual`
606-
function (or the `combine='manual'` option to open_mfdataset).""")
602+
to use the new `combine_by_coords` function (or the
603+
`combine='by_coords'` option to `open_mfdataset` to order the datasets
604+
before concatenation. Alternatively, to continue concatenating based
605+
on the order the datasets are supplied in in future, please use the
606+
new `combine_nested` function (or the `combine='nested'` option to
607+
open_mfdataset).""")
607608
else:
608609
message += dedent("""\
609610
The datasets supplied do not have global dimension coordinates. In
610611
future, to continue concatenating without supplying dimension
611-
coordinates, please use the new `combine_manual` function (or the
612-
`combine='manual'` option to open_mfdataset.""")
612+
coordinates, please use the new `combine_nested` function (or the
613+
`combine='nested'` option to open_mfdataset.""")
613614

614615
if _requires_concat_and_merge(datasets):
615616
manual_dims = [concat_dim].append(None)
616617
message += dedent("""\
617618
The datasets supplied require both concatenation and merging. From
618619
xarray version 0.14 this will operation will require either using the
619-
new `combine_manual` function (or the `combine='manual'` option to
620+
new `combine_nested` function (or the `combine='nested'` option to
620621
open_mfdataset), with a nested list structure such that you can combine
621622
along the dimensions {}. Alternatively if your datasets have global
622-
dimension coordinates then you can use the new `combine_auto` function.
623-
""".format(manual_dims))
623+
dimension coordinates then you can use the new `combine_by_coords`
624+
function.""".format(manual_dims))
624625

625626
warnings.warn(message, FutureWarning, stacklevel=2)
626627

0 commit comments

Comments
 (0)