modelrunner.storage.utils module

Functions and classes that are used commonly used by the storage classes.

class Array(input_array, attrs=None)[source]

Bases: ndarray

Numpy array augmented with attributes

Parameters:

attrs (Attrs | None) –

decode_binary(obj_str)[source]

decode an object encoded with encode_binary().

Parameters:

obj_str (str or bytes) – The string that encodes the object

Returns:

the object

Return type:

Any

decode_class(class_path, *, guess=None)[source]

decode a class encoded with encode_class().

Parameters:
  • class_path (str) – The string that encodes the class

  • guess (type) – A class that is used if the encoded class cannot be found and the name of the guess matches the encoded class.

Returns:

the class or None if class_path was None

Return type:

type

encode_binary(obj: Any, *, binary: Literal[True]) bytes[source]
encode_binary(obj: Any, *, binary: Literal[False]) str

encodes an arbitrary object as a string

The object can be decoded using decode_binary().

Parameters:
  • obj – The object to encode

  • binary (bool) – Encode as a byte array if True. Otherwise, a unicode string is returned

Returns:

The encoded object

Return type:

str or bytes

encode_class(cls)[source]

encode a class such that it can be restored

The class can be decoded using decode_class().

Parameters:

cls (type) – The class

Returns:

the encoded class

Return type:

str