Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow in-memory arrays with open_mfdataset #5704

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Deprecations
Bug fixes
~~~~~~~~~

- Allow in-memory arrays with :py:func:`xarray.open_mfdataset` by passing ``chunks=None``. (:pull:`5704`).
By `Jimmy Westling <https://github.com/illviljan>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ def open_datatree(

def open_mfdataset(
paths: str | NestedSequence[str | os.PathLike],
chunks: T_Chunks | None = None,
chunks: T_Chunks | None = {},
concat_dim: (
str
| DataArray
Expand Down Expand Up @@ -858,7 +858,7 @@ def open_mfdataset(
concatenation along more than one dimension is desired, then ``paths`` must be a
nested list-of-lists (see ``combine_nested`` for details). (A string glob will
be expanded to a 1-dimensional list.)
chunks : int, dict, 'auto' or None, optional
chunks : int, dict, 'auto' or None, default: {}
Dictionary with keys given by dimension names and values given by chunk sizes.
In general, these should divide the dimensions of each dataset. If int, chunk
each dimension by ``chunks``. By default, chunks will be chosen to load entire
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def open_mfdataset(
"instead specify combine='nested' along with a value for `concat_dim`.",
)

open_kwargs = dict(engine=engine, chunks=chunks or {}, **kwargs)
open_kwargs = dict(engine=engine, chunks=chunks, **kwargs)

if parallel:
import dask
Expand Down
11 changes: 8 additions & 3 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3947,7 +3947,7 @@
return request.param


@pytest.fixture(params=[None, 5])
@pytest.fixture(params=[None, {}, 5])
def chunks(request):
return request.param

Expand Down Expand Up @@ -3999,16 +3999,21 @@
subds.to_zarr(store=tmpfiles[ii])

# check that calculation on opened datasets works properly
chunks = chunks if (not chunks and readengine != "zarr") else "auto"
with open_mfdataset(
tmpfiles,
combine="nested",
concat_dim="x",
engine=readengine,
parallel=parallel,
chunks=chunks if (not chunks and readengine != "zarr") else "auto",
chunks=chunks,
) as actual:
# check that using open_mfdataset returns dask arrays for variables
assert isinstance(actual["foo"].data, dask_array_type)
# when a chunks parameter has been defined:
if chunks is None:
assert isinstance(actual["foo"].data, np.ndarray)
else:
assert isinstance(actual["foo"].data, dask_array_type)

assert_identical(original, actual)

Expand Down Expand Up @@ -4688,7 +4693,7 @@
with open_dataset(tmp, chunks=chunks) as dask_ds:
assert_identical(data, dask_ds)
with create_tmp_file() as tmp2:
dask_ds.to_netcdf(tmp2)

Check failure on line 4696 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12 flaky

TestDask.test_dask_roundtrip Failed: Timeout >180.0s
with open_dataset(tmp2) as on_disk:
assert_identical(data, on_disk)

Expand Down
Loading