diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 03b10d1d73c..7025e2dd7d9 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -208,6 +208,10 @@ Bug fixes when objects other than ``Dataset`` are provided (:issue:`1555`). By `Joe Hamman `_. +- :py:func:`xarray.concat` would eagerly load dask variables into memory if + the first argument was a numpy variable (:issue:`1588`). + By `Guido Imperiale `_. + .. _whats-new.0.9.6: v0.9.6 (8 June 2017) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index 394e7182435..2f97de4a1ba 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -40,9 +40,11 @@ def _dask_or_eager_func(name, eager_module=np, list_of_args=False, """Create a function that dispatches to dask for dask array inputs.""" if has_dask: def f(*args, **kwargs): - dispatch_args = args[0] if list_of_args else args - if any(isinstance(a, da.Array) - for a in dispatch_args[:n_array_args]): + if list_of_args: + dispatch_args = args[0] + else: + dispatch_args = args[:n_array_args] + if any(isinstance(a, da.Array) for a in dispatch_args): module = da else: module = eager_module diff --git a/xarray/tests/test_dask.py b/xarray/tests/test_dask.py index 7e2bf868b31..fdb2ff715dd 100644 --- a/xarray/tests/test_dask.py +++ b/xarray/tests/test_dask.py @@ -178,6 +178,8 @@ def test_concat(self): v = self.lazy_var self.assertLazyAndIdentical(u, Variable.concat([v[:2], v[2:]], 'x')) self.assertLazyAndIdentical(u[:2], Variable.concat([v[0], v[1]], 'x')) + self.assertLazyAndIdentical(u[:2], Variable.concat([u[0], v[1]], 'x')) + self.assertLazyAndIdentical(u[:2], Variable.concat([v[0], u[1]], 'x')) self.assertLazyAndIdentical( u[:3], Variable.concat([v[[0, 2]], v[[1]]], 'x', positions=[[0, 2], [1]]))