Data API

These are the built-in classes and services to manage dataflow types.

class ml.data.Number(value: Any)

Bases: object

A wrapper class for numeric types to centralize control over precision and implementation, primarily for Decimal.

DECIMAL = 'DECIMAL'
FLOAT = 'FLOAT'
NUMPY = 'NUMPY'
static configure(conf: Any)

Configures the global precision for Number operations based on the provided configuration object. This should be called once at startup.

Parameters:

conf – The configuration object containing ‘NUMBER_IMPLEMENTATION’ and optionally ‘DECIMAL_CONTEXT_PRECISION’.

Raises:
  • ValueError – If ‘NUMBER_IMPLEMENTATION’ is missing or if ‘DECIMAL_CONTEXT_PRECISION’ is missing when implementation is DECIMAL.

  • NotImplementedError – If the implementation is not supported.

static precision() int

Returns the configured precision.

Returns:

The configured precision.

Return type:

int

Raises:

RuntimeError – If called before configure() for DECIMAL implementation.

static set_context()

Sets the thread-local decimal precision for PythonDecimal operations. This is only active if the implementation is ‘DECIMAL’.

Raises:

RuntimeError – If called before configure().

ml.data.configure(conf: Any)

Calls the configure() static method on all registered classes. This should be called once per process.

ml.data.register_data_type(cls: Type)

Registers a class.

Parameters:

cls (Type) – The class to register.

ml.data.set_context()

Calls the set_context() static method on all registered classes. This should be called once per process/thread.