Skip to content

Commit

Permalink
Remove old auto combine (#3926)
Browse files Browse the repository at this point in the history
* Removed auto_combine function and argument to open_mfdataset

* Removed corresponding tests

* Code formatting

* updated what's new

* PEP8 fixes

* Update doc/whats-new.rst

`:py:func:` links fixed

Co-Authored-By: keewis <[email protected]>

* removed auto_combine from API docs

* clarify that auto_combine is completely removed

* concat_dim=None by default for combine='nested'

* fix black formatting

Co-authored-by: keewis <[email protected]>
Co-authored-by: dcherian <[email protected]>
  • Loading branch information
3 people authored Jun 24, 2020
1 parent 24d755d commit 3088de2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 573 deletions.
2 changes: 0 additions & 2 deletions doc/api-hidden.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
.. autosummary::
:toctree: generated/

auto_combine

Dataset.nbytes
Dataset.chunks

Expand Down
1 change: 0 additions & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Top-level functions
broadcast
concat
merge
auto_combine
combine_by_coords
combine_nested
where
Expand Down
7 changes: 7 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ Breaking changes
<https://matplotlib.org/api/prev_api_changes/api_changes_3.1.0.html#passing-a-line2d-s-drawstyle-together-with-the-linestyle-is-deprecated>`_.
(:pull:`3274`)
By `Elliott Sales de Andrade <https://github.com/QuLogic>`_
- The old :py:func:`auto_combine` function has now been removed in
favour of the :py:func:`combine_by_coords` and
:py:func:`combine_nested` functions. This also means that
the default behaviour of :py:func:`open_mfdataset` has changed to use
``combine='by_coords'`` as the default argument value. (:issue:`2616`, :pull:`3926`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.


Enhancements
~~~~~~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .coding.frequencies import infer_freq
from .conventions import SerializationWarning, decode_cf
from .core.alignment import align, broadcast
from .core.combine import auto_combine, combine_by_coords, combine_nested
from .core.combine import combine_by_coords, combine_nested
from .core.common import ALL_DIMS, full_like, ones_like, zeros_like
from .core.computation import apply_ufunc, corr, cov, dot, polyval, where
from .core.concat import concat
Expand Down Expand Up @@ -47,7 +47,6 @@
"align",
"apply_ufunc",
"as_variable",
"auto_combine",
"broadcast",
"cftime_range",
"combine_by_coords",
Expand Down
61 changes: 16 additions & 45 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from io import BytesIO
from numbers import Number
from pathlib import Path
from textwrap import dedent
from typing import (
TYPE_CHECKING,
Callable,
Expand All @@ -23,7 +22,6 @@
from ..core.combine import (
_infer_concat_order_from_positions,
_nested_combine,
auto_combine,
combine_by_coords,
)
from ..core.dataarray import DataArray
Expand Down Expand Up @@ -726,14 +724,14 @@ def close(self):
def open_mfdataset(
paths,
chunks=None,
concat_dim="_not_supplied",
concat_dim=None,
compat="no_conflicts",
preprocess=None,
engine=None,
lock=None,
data_vars="all",
coords="different",
combine="_old_auto",
combine="by_coords",
autoclose=None,
parallel=False,
join="outer",
Expand All @@ -746,9 +744,8 @@ def open_mfdataset(
the datasets into one before returning the result, and if combine='nested' then
``combine_nested`` is used. The filepaths must be structured according to which
combining function is used, the details of which are given in the documentation for
``combine_by_coords`` and ``combine_nested``. By default the old (now deprecated)
``auto_combine`` will be used, please specify either ``combine='by_coords'`` or
``combine='nested'`` in future. Requires dask to be installed. See documentation for
``combine_by_coords`` and ``combine_nested``. By default ``combine='by_coords'``
will be used. Requires dask to be installed. See documentation for
details on dask [1]_. Global attributes from the ``attrs_file`` are used
for the combined dataset.
Expand All @@ -758,7 +755,7 @@ def open_mfdataset(
Either a string glob in the form ``"path/to/my/files/*.nc"`` or an explicit list of
files to open. Paths can be given as strings or as pathlib Paths. If
concatenation along more than one dimension is desired, then ``paths`` must be a
nested list-of-lists (see ``manual_combine`` for details). (A string glob will
nested list-of-lists (see ``combine_nested`` for details). (A string glob will
be expanded to a 1-dimensional list.)
chunks : int or dict, optional
Dictionary with keys given by dimension names and values given by chunk sizes.
Expand All @@ -768,15 +765,16 @@ def open_mfdataset(
see the full documentation for more details [2]_.
concat_dim : str, or list of str, DataArray, Index or None, optional
Dimensions to concatenate files along. You only need to provide this argument
if any of the dimensions along which you want to concatenate is not a dimension
in the original datasets, e.g., if you want to stack a collection of 2D arrays
along a third dimension. Set ``concat_dim=[..., None, ...]`` explicitly to
disable concatenation along a particular dimension.
if ``combine='by_coords'``, and if any of the dimensions along which you want to
concatenate is not a dimension in the original datasets, e.g., if you want to
stack a collection of 2D arrays along a third dimension. Set
``concat_dim=[..., None, ...]`` explicitly to disable concatenation along a
particular dimension. Default is None, which for a 1D list of filepaths is
equivalent to opening the files separately and then merging them with
``xarray.merge``.
combine : {'by_coords', 'nested'}, optional
Whether ``xarray.combine_by_coords`` or ``xarray.combine_nested`` is used to
combine all the data. If this argument is not provided, `xarray.auto_combine` is
used, but in the future this behavior will switch to use
`xarray.combine_by_coords` by default.
combine all the data. Default is to use ``xarray.combine_by_coords``.
compat : {'identical', 'equals', 'broadcast_equals',
'no_conflicts', 'override'}, optional
String indicating how to compare variables of the same name for
Expand Down Expand Up @@ -869,7 +867,6 @@ def open_mfdataset(
--------
combine_by_coords
combine_nested
auto_combine
open_dataset
References
Expand Down Expand Up @@ -897,11 +894,8 @@ def open_mfdataset(
# If combine='nested' then this creates a flat list which is easier to
# iterate over, while saving the originally-supplied structure as "ids"
if combine == "nested":
if str(concat_dim) == "_not_supplied":
raise ValueError("Must supply concat_dim when using " "combine='nested'")
else:
if isinstance(concat_dim, (str, DataArray)) or concat_dim is None:
concat_dim = [concat_dim]
if isinstance(concat_dim, (str, DataArray)) or concat_dim is None:
concat_dim = [concat_dim]
combined_ids_paths = _infer_concat_order_from_positions(paths)
ids, paths = (list(combined_ids_paths.keys()), list(combined_ids_paths.values()))

Expand Down Expand Up @@ -933,30 +927,7 @@ def open_mfdataset(

# Combine all datasets, closing them in case of a ValueError
try:
if combine == "_old_auto":
# Use the old auto_combine for now
# Remove this after deprecation cycle from #2616 is complete
basic_msg = dedent(
"""\
In xarray version 0.15 the default behaviour of `open_mfdataset`
will change. To retain the existing behavior, pass
combine='nested'. To use future default behavior, pass
combine='by_coords'. See
http://xarray.pydata.org/en/stable/combining.html#combining-multi
"""
)
warnings.warn(basic_msg, FutureWarning, stacklevel=2)

combined = auto_combine(
datasets,
concat_dim=concat_dim,
compat=compat,
data_vars=data_vars,
coords=coords,
join=join,
from_openmfds=True,
)
elif combine == "nested":
if combine == "nested":
# Combined nested list by successive concat and merge operations
# along each dimension, using structure given by "ids"
combined = _nested_combine(
Expand Down
Loading

0 comments on commit 3088de2

Please sign in to comment.