Repository navigation
Closed
Labels
Description
What happened:
When building the Fedora package of xarray 0.18.0/0.18.1, test_push_dask failed. This did not happen in previous versions (or the test did not exist then.)
Minimal Complete Verifiable Example:
________________________________ test_push_dask ________________________________
[gw2] linux -- Python 3.9.5 /usr/bin/python3
@requires_dask
@requires_bottleneck
def test_push_dask():
import bottleneck
import dask.array
array = np.array([np.nan, np.nan, np.nan, 1, 2, 3, np.nan, np.nan, 4, 5, np.nan, 6])
expected = bottleneck.push(array, axis=0)
for c in range(1, 11):
with raise_if_dask_computes():
> actual = push(dask.array.from_array(array, chunks=c), axis=0, n=None)
/builddir/build/BUILDROOT/python-xarray-0.18.1-1.fc35.x86_64/usr/lib/python3.9/site-packages/xarray/tests/test_duck_array_ops.py:886:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/builddir/build/BUILDROOT/python-xarray-0.18.1-1.fc35.x86_64/usr/lib/python3.9/site-packages/xarray/core/duck_array_ops.py:663: in push
return dask_array_ops.push(array, n, axis)
/builddir/build/BUILDROOT/python-xarray-0.18.1-1.fc35.x86_64/usr/lib/python3.9/site-packages/xarray/core/dask_array_ops.py:69: in push
pushed = array.map_blocks(push, axis=axis, n=n)
/usr/lib/python3.9/site-packages/dask/array/core.py:2333: in map_blocks
return map_blocks(func, self, *args, **kwargs)
/usr/lib/python3.9/site-packages/dask/array/core.py:683: in map_blocks
dtype = apply_infer_dtype(func, args, original_kwargs, "map_blocks")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
func = <built-in function push>, args = [array([1.])]
kwargs = {'axis': 0, 'n': None}, funcname = 'map_blocks'
suggest_dtype = 'dtype', nout = None
def apply_infer_dtype(func, args, kwargs, funcname, suggest_dtype="dtype", nout=None):
"""
Tries to infer output dtype of ``func`` for a small set of input arguments.
Parameters
----------
func: Callable
Function for which output dtype is to be determined
args: List of array like
Arguments to the function, which would usually be used. Only attributes
``ndim`` and ``dtype`` are used.
kwargs: dict
Additional ``kwargs`` to the ``func``
funcname: String
Name of calling function to improve potential error messages
suggest_dtype: None/False or String
If not ``None`` adds suggestion to potential error message to specify a dtype
via the specified kwarg. Defaults to ``'dtype'``.
nout: None or Int
``None`` if function returns single output, integer if many.
Deafults to ``None``.
Returns
-------
: dtype or List of dtype
One or many dtypes (depending on ``nout``)
"""
args = [
np.ones((1,) * x.ndim, dtype=x.dtype) if isinstance(x, Array) else x
for x in args
]
try:
with np.errstate(all="ignore"):
o = func(*args, **kwargs)
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
tb = "".join(traceback.format_tb(exc_traceback))
suggest = (
(
"Please specify the dtype explicitly using the "
"`{dtype}` kwarg.\n\n".format(dtype=suggest_dtype)
)
if suggest_dtype
else ""
)
msg = (
"`dtype` inference failed in `{0}`.\n\n"
"{1}"
"Original error is below:\n"
"------------------------\n"
"{2}\n\n"
"Traceback:\n"
"---------\n"
"{3}"
).format(funcname, suggest, repr(e), tb)
else:
msg = None
if msg is not None:
> raise ValueError(msg)
E ValueError: `dtype` inference failed in `map_blocks`.
E
E Please specify the dtype explicitly using the `dtype` kwarg.
E
E Original error is below:
E ------------------------
E TypeError('`n` must be an integer')
E
E Traceback:
E ---------
E File "/usr/lib/python3.9/site-packages/dask/array/core.py", line 383, in apply_infer_dtype
E o = func(*args, **kwargs)
/usr/lib/python3.9/site-packages/dask/array/core.py:408: ValueErrorAnything else we need to know?:
Environment:
Output of xr.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.9.5 (default, May 4 2021, 00:00:00)
[GCC 11.1.1 20210428 (Red Hat 11.1.1-1)]
python-bits: 64
OS: Linux
OS-release: 5.11.19-300.fc34.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.10.6
libnetcdf: 4.7.3
xarray: 0.18.1
pandas: 1.2.1
numpy: 1.20.1
scipy: 1.6.2
netCDF4: 1.5.6
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.8.1
cftime: 1.4.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.2.1
cfgrib: None
iris: None
bottleneck: 1.2.1
dask: 2021.04.1
distributed: None
matplotlib: 3.4.2
cartopy: None
seaborn: None
numbagg: None
pint: 0.16.1
setuptools: 56.1.0
pip: None
conda: None
pytest: 6.2.4
IPython: None
sphinx: None
Activity
dcherian commentedon May 19, 2021
Thanks. This is a new test.
Here's where the error is triggered:
xarray/xarray/core/dask_array_ops.py
Lines 69 to 73 in f3794ab
We should specify both
dtypeandmetain themap_*calls like this:Can you send in a PR please?
QuLogic commentedon May 20, 2021
That seems insufficient:
________________________________ test_push_dask ________________________________ [gw3] linux -- Python 3.9.5 /usr/bin/python3 @requires_dask @requires_bottleneck def test_push_dask(): import bottleneck import dask.array array = np.array([np.nan, np.nan, np.nan, 1, 2, 3, np.nan, np.nan, 4, 5, np.nan, 6]) expected = bottleneck.push(array, axis=0) for c in range(1, 11): with raise_if_dask_computes(): actual = push(dask.array.from_array(array, chunks=c), axis=0, n=None) > np.testing.assert_equal(actual, expected) /builddir/build/BUILDROOT/python-xarray-0.18.2-1.fc35.x86_64/usr/lib/python3.9/site-packages/xarray/tests/test_duck_array_ops.py:887: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3.9/site-packages/dask/array/core.py:1476: in __array__ x = self.compute() /usr/lib/python3.9/site-packages/dask/base.py:285: in compute (result,) = compute(self, traverse=False, **kwargs) /usr/lib/python3.9/site-packages/dask/base.py:567: in compute results = schedule(dsk, keys, **kwargs) /usr/lib/python3.9/site-packages/dask/local.py:560: in get_sync return get_async( /usr/lib/python3.9/site-packages/dask/local.py:503: in get_async for key, res_info, failed in queue_get(queue).result(): /usr/lib64/python3.9/concurrent/futures/_base.py:438: in result return self.__get_result() /usr/lib64/python3.9/concurrent/futures/_base.py:390: in __get_result raise self._exception /usr/lib/python3.9/site-packages/dask/local.py:545: in submit fut.set_result(fn(*args, **kwargs)) /usr/lib/python3.9/site-packages/dask/local.py:237: in batch_execute_tasks return [execute_task(*a) for a in it] /usr/lib/python3.9/site-packages/dask/local.py:237: in <listcomp> return [execute_task(*a) for a in it] /usr/lib/python3.9/site-packages/dask/local.py:228: in execute_task result = pack_exception(e, dumps) /usr/lib/python3.9/site-packages/dask/local.py:223: in execute_task result = _execute_task(task, data) /usr/lib/python3.9/site-packages/dask/core.py:121: in _execute_task return func(*(_execute_task(a, cache) for a in args)) /usr/lib/python3.9/site-packages/dask/optimization.py:963: in __call__ return core.get(self.dsk, self.outkey, dict(zip(self.inkeys, args))) /usr/lib/python3.9/site-packages/dask/core.py:151: in get result = _execute_task(task, cache) /usr/lib/python3.9/site-packages/dask/core.py:121: in _execute_task return func(*(_execute_task(a, cache) for a in args)) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ func = <built-in function push>, args = [array([nan, 1.])] kwargs = {'axis': 0, 'n': None} def apply(func, args, kwargs=None): if kwargs: > return func(*args, **kwargs) E TypeError: `n` must be an integer /usr/lib/python3.9/site-packages/dask/utils.py:34: TypeErrordcherian commentedon May 20, 2021
What version of bottleneck are you testing it with? We require
bottleneck >=1.3(https://github.com/pydata/xarray/blob/master/ci/requirements/py37-min-all-deps.yml)keewis commentedon May 20, 2021
for reference, the failing call is:
which should work with
bottleneck>=1.3(I can reproduce the failure withbottleneck=1.2.1, which is the one you have in your environment).QuLogic commentedon May 20, 2021
Ah, you're right, it's still 1.2.1, I'll fix that.
dcherian commentedon May 26, 2021
We should still make the changes proposed in #5342 (comment)
QuLogic commentedon Jul 4, 2021
This should go in
setup.cfg, then? I'm not using conda.