caikit.core.data_model.streams.validator

DataStream validator that validates that a datastream includes the expected parts - for dictionaries, that all expected dictionary keys exist, and for iterables, that the iterable length is the expected length. The types of the internal elements of each item are also validated.

Attributes

log

error

Classes

DataStreamValidator

Validates that DataStreams contain the expected data items based on type

Module Contents

caikit.core.data_model.streams.validator.log[source]
caikit.core.data_model.streams.validator.error
class caikit.core.data_model.streams.validator.DataStreamValidator(expected_keys: Dict[str, type])[source]

Validates that DataStreams contain the expected data items based on type

_expected_keys: Dict[str, type]
validate(stream: caikit.core.data_model.DataStream) caikit.core.data_model.DataStream[source]

Attempt to validate the data items in a data stream (lazily)

Validation checks: 1. That the data in the stream is either a dictionary or list or tuple 2. In the case of dictionaries, all expected keys exist and the values are the types given in

self._expected_keys

  1. In the case of iterables, that the length of each iterable matches the expected number of

    items and the type of the nth item matches the nth type in self._expected_keys

Args:

stream (DataStream): stream intended to be converted

Returns:

The same data stream, which will now throw DataValidationErrors when accessed if the data is not valid.

_validate_data(data_item: object, data_item_number: int) None[source]

Validate a single data item from a data stream

Args:

data_item: A data object yielded by the stream data_item_number: The index of the object in the stream