Data types and protocols used by OpenFisca Core.

The type definitions included in this sub-package are intented for contributors, to help them better understand and document contracts and expected behaviours.

Official Public API:


How imports are being used today:

from openfisca_core.types import *  # Bad
from openfisca_core.types.data_types.arrays import ArrayLike  # Bad

The previous examples provoke cyclic dependency problems, that prevents us from modularizing the different components of the library, so as to make them easier to test and to maintain.

How could them be used after the next major release:

from openfisca_core.types import ArrayLike

ArrayLike # Good: import types as publicly exposed

alias of nptyping.types._ndarray.NDArray


Type of any castable to numpy.ndarray.

These include any numpy.ndarray and sequences (like list, tuple, and so on).


>>> ArrayLike[float]
typing.Union[numpy.ndarray, typing.Sequence[float]]
>>> ArrayLike[str]
typing.Union[numpy.ndarray, typing.Sequence[str]]


It is possible since numpy version 1.21 to specify the type of an array, thanks to numpy.typing.NDArray:

from numpy.typing import NDArray

mypy provides duck type compatibility, so an int is considered to be valid whenever a float is expected.

New in version 35.5.0.

Changed in version 35.6.0: Moved to types



alias of Union[nptyping.types._ndarray.NDArray, Sequence[openfisca_core.types.data_types.arrays.T]]