bagof.hints.dask
Hints for [dask.array][] arrays.
dask reuses numpy's data types, so this module only defines the array type
itself; dtype, DTypeLike and the protocols are re-exported from
bagof.hints.numpy and bagof.hints.array.
Note
This module is not imported by bagof.hints, so that importing the
package never imports dask. It stays importable when dask is absent, in
which case Array degrades to an empty generic stub.
Attributes
NDArray
module-attribute
A dask array of arbitrary shape, parametrised by its data type.
Classes
ArrayNamespace
Bases: Protocol
An object that implements the Python array API standard.
This is the modern, portable alternative to ArrayProtocol: rather
than converting to a numpy array, it exposes the namespace of the
library that owns the object, so that library-agnostic code can call
xp.mean(x) without knowing which library x came from.
See https://data-apis.org/array-api/latest/.
Tip
Prefer this over ArrayProtocol when the goal is to stay in
the originating library (and off the host, for GPU arrays), since
__array__ forces a conversion to numpy.
ArrayProtocol
Bases: Protocol
An object that can be converted to an array.
This is the oldest and most widely implemented array hook: numpy, cupy,
dask, torch and pandas objects all provide it, so a single structural
check covers them all. See numpy.ndarray.__array__.
Example
DTypeProtocol
Bases: Protocol[DTYPE]
An object that carries a data type.
Any array, and any numpy.dtype-like object, satisfies this. The
parameter is the type of the dtype attribute itself; it is invariant,
because the protocol declares a mutable attribute rather than a
read-only property.
dtype
Bases: Generic[DTYPE]
A generic stub for numpy.dtype.
Array
Bases: Generic[SHAPE, DTYPE]
A generic stub for dask.array.Array.