Skip to content

typing

Type hinting utils, defined and exposed for code readability purposes.

Batch = Tuple[Union[ArrayLike, List[ArrayLike]], Optional[Union[ArrayLike, List[ArrayLike]]], Optional[ArrayLike]] module-attribute

Data batches specification type-annotation.

This type-hint designates (inputs, labels, weights) inputs, where:

  • inputs and labels may be an array or a list of arrays;
  • labels and/or weights may be None;

DataArray = Union[np.ndarray, pd.DataFrame, pd.Series, spmatrix] module-attribute

Type-annotation alias for a union of data type structures.

This alias covers types supported by declearn.dataset.utils.save_data_array and its counterpart declearn.dataset.utils.load_data_array, and is hence used to annotate some dataset-interfacing tools under declearn.dataset.

SupportsConfig

Bases: Protocol

Protocol for type annotation of objects with get/from_config methods.

This class is primarily designed to be used for type annotation, but may also be used to implement get_config and from_config the former of which requires overriding.

Source code in declearn/typing.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class SupportsConfig(Protocol, metaclass=ABCMeta):
    """Protocol for type annotation of objects with get/from_config methods.

    This class is primarily designed to be used for type annotation,
    but may also be used to implement `get_config` and `from_config`
    the former of which requires overriding.
    """

    @abstractmethod
    def get_config(self) -> Dict[str, Any]:
        """Return a JSON-serializable config dict representing this object."""
        return {}

    @classmethod
    def from_config(
        cls,
        config: Dict[str, Any],
    ) -> Self:
        """Instantiate an object from its JSON-serializable config dict."""
        return cls(**config)

from_config(config) classmethod

Instantiate an object from its JSON-serializable config dict.

Source code in declearn/typing.py
73
74
75
76
77
78
79
@classmethod
def from_config(
    cls,
    config: Dict[str, Any],
) -> Self:
    """Instantiate an object from its JSON-serializable config dict."""
    return cls(**config)

get_config() abstractmethod

Return a JSON-serializable config dict representing this object.

Source code in declearn/typing.py
68
69
70
71
@abstractmethod
def get_config(self) -> Dict[str, Any]:
    """Return a JSON-serializable config dict representing this object."""
    return {}