Skip to content

DataReader

The DataReader is a base class for which may be used to generate data that is processed by PZ.

Subclasses of the (abstract) DataReader class must implement two methods:

  • __len__(): which returns the number of elements in the data source
  • __getitem__(idx: int): which takes in an idx and returns the element at that index

__init__

__init__(schema: type[Schema] | list[dict]) -> None

Constructor for the DataReader class.

Parameters:

  • schema (Schema | list[dict]) –

    The output schema of the records returned by the DataReader

__len__ abstractmethod

__len__() -> int

Returns the number of items in the data reader.

__getitem__ abstractmethod

__getitem__(idx: int) -> dict

Returns a single item from the data reader at the given index.

Parameters:

  • idx (int) –

    The index of the item to return

Returns:

  • dict ( dict ) –

    A dictionary representing the item at the given index. The dictionary keys (i.e. fields) should match the fields specified in the schema of the data source, and the values should be the values associated with those fields.

    # Example return value
    {"field1": value1, "field2": value2, ...}