Description
If I use the sum
method on a lazy array with min_count != None
then evaluation is forced. If there is some limitation of the implementation which means it cannot be added to the computation graph for lazy evaluation then this should be mentioned in the docs.
Minimal Complete Verifiable Example:
import numpy as np
import xarray as xr
def worker(da):
if da.shape == (0, 0):
return da
raise RuntimeError("I was evaluated")
da = xr.DataArray(
np.random.normal(size=(20, 500)),
dims=("x", "y"),
coords=(np.arange(20), np.arange(500)),
)
da = da.chunk(dict(x=5))
lazy = da.map_blocks(worker)
result1 = lazy.sum("x", skipna=True)
result2 = lazy.sum("x", skipna=True, min_count=5)
What happened: RuntimeError: I was evaluated
What you expected to happen: No output or exceptions, as the result1 and result2 arrays are not printed or saved.
Environment:
Output of xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.9.1 (default, Feb 6 2021, 06:49:13)
[GCC 10.2.0]
python-bits: 64
OS: Linux
OS-release: 5.10.15-arch1-1
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_NZ.UTF-8
LOCALE: en_NZ.UTF-8
libhdf5: 1.12.0
libnetcdf: 4.7.4
xarray: 0.16.2
pandas: 1.2.1
numpy: 1.20.0
scipy: 1.6.0
netCDF4: 1.5.5.1
pydap: None
h5netcdf: 0.9.0
h5py: 3.1.0
Nio: None
zarr: None
cftime: 1.4.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.2.0
cfgrib: None
iris: None
bottleneck: 1.3.2
dask: 2020.12.0
distributed: 2020.12.0
matplotlib: 3.3.4
cartopy: 0.18.0
seaborn: None
numbagg: None
pint: None
setuptools: 53.0.0
pip: 20.3.1
conda: None
pytest: 6.2.1
IPython: 7.19.0
sphinx: 3.4.3