Dask

Interface for Dask arrays

class DaskJsonDict(*, type: Literal['dask'], name: str, chunks: Iterable[tuple[int, ...]], dtype: str, shape: tuple[int, ...] | None = None, value: list)[source]

Round-trip json serialized form of a dask array

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

to_array_input() Array[source]

Construct a dask array

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class DaskTyping[source]

Static-typing companion for DaskInterface.

constructors: ClassVar[tuple[ConstructorSpec, ...]] = (ConstructorSpec(fullname='dask.array.zeros', shape_arg=0, dtype_arg='dtype', mode='function'), ConstructorSpec(fullname='dask.array.ones', shape_arg=0, dtype_arg='dtype', mode='function'), ConstructorSpec(fullname='dask.array.empty', shape_arg=0, dtype_arg='dtype', mode='function'), ConstructorSpec(fullname='dask.array.full', shape_arg=0, dtype_arg='dtype', mode='function'))

Constructor calls whose return type the mypy plugin should refine.

classmethod emit_imports() list[str][source]

import dask.array and numpy

classmethod emit_constructor_source(shape: tuple[int, ...], dtype: str) str | None[source]

render a call to dask.array.zeros

class DaskInterface(shape: tuple[int, ...] | Any = typing.Any, dtype: str | type | Any | generic = typing.Any)[source]

Interface for Dask Array

return_type

alias of Array

json_model

alias of DaskJsonDict

typing

alias of DaskTyping

classmethod check(array: Any) bool[source]

check if array is a dask array

before_validation(array: Array) NDArrayType[source]

Try and coerce dicts that should be model objects into the model objects

get_object_dtype(array: NDArrayType) str | type | Any | generic[source]

Dask arrays require a compute() call to retrieve a single value

classmethod enabled() bool[source]

check if we successfully imported dask

classmethod to_json(array: Array, info: SerializationInfo | None = None) list | DaskJsonDict[source]

Convert an array to a JSON serializable array by first converting to a numpy array and then to a list.

Note

This is likely a very memory intensive operation if you are using dask for large arrays. This can’t be avoided, since the creation of the json string happens in-memory with Pydantic, so you are likely looking for a different method of serialization here using the python object itself rather than its JSON representation.