daf.typing.unions

Union types used in the rest of the code.

These types capture important concepts that allow generic daf functions to clearly express their intent. Due to to limitations of mypy, the existing type annotations in numpy and the lack of type annotations in scipy.sparse and pandas, the Known... types are too permissive, but the is_known.../be_known... functions do the right thing.

Data:

AnyData

"Any" data that can be used to construct "proper" 1D/2D data.

Known

Any 1D/2D data type that daf knows about.

Known1D

Any 1D data type that daf knows about.

Known2D

Any 2D data type that daf knows about.

Proper

Any "proper" 1D/2D data type that daf fully supports.

Proper1D

Any "proper" 1D data type that daf fully supports.

Proper2D

Any "proper" 2D data type that daf fully supports.

ProperInRows

Any "proper" ROW_MAJOR 2D data type that daf fully supports.

ProperInColumns

Any "proper" COLUMN_MAJOR 2D data type that daf fully supports.

Functions:

is_known(data)

Assert that some data is Known (and actually 1D/2D data), and return it as such for mypy.

be_known(data)

Assert that some data is Known (and actually 1D/2D data), and return it as such for mypy.

is_known1d(data)

Assert that some data is Known1D (and actually 1D data).

be_known1d(data)

Assert that some data is Known1D, and return it as such for mypy.

is_known2d(data)

Assert that some data is Known2D (and actually 2D data).

be_known2d(data)

Assert that some data is Known2D (and actually 2D data), and return it as such for mypy.

is_proper(data, *[, dtype])

Assert that some data is Proper, optionally only of some dtype.

be_proper(data, *[, dtype])

Assert that some data is Proper, optionally only of some dtype, and return it as such for mypy.

is_proper1d(data, *[, dtype, size])

Assert that some data is Proper1D,, optionally only of some dtype, optionally only of some size.

be_proper1d(data, *[, dtype, size])

Assert that some data is Proper1D, optionally only of some dtype, optionally only of some size, and return it as such for mypy.

is_proper2d(data, *[, dtype, shape, layout])

Assert that some data is Proper2D, optionally only of some dtype, optionally only of some shape, optionally optionally only of a specific layout.

be_proper2d(data, *[, dtype, shape, layout])

Assert that some data is Proper2D, optionally only of some dtype, optionally only of some shape, optionally optionally only of a specific layout, and return it as such for mypy.

is_proper_in_rows(data, *[, dtype, shape])

Assert that some data is ProperInRows.

be_proper_in_rows(data, *[, dtype, shape])

Assert that some data is ProperInRows, optionally only of some dtype, optionally only of some shape, and return it as such for mypy.

is_proper_in_columns(data, *[, dtype, shape])

Assert that some data is ProperInColumns, optionally only of some dtype, optionally only of some shape.

be_proper_in_columns(data, *[, dtype, shape])

Assert that some data is ProperInColumns, optionally only of some dtype, optionally only of some shape, and return it as such for mypy.

daf.typing.unions.AnyData(*args, **kwargs)

“Any” data that can be used to construct “proper” 1D/2D data.

We don’t distinguish between 1D and 2D data here, because one can use 2D-ish data with an axis of size 1 to construct 1D data (that is, a matrix with a single row can be used to construct a vector).

There are probably other alternatives that should be listed here, but this covers most usages.

alias of Union[Sequence[Any], ndarray, _fake_sparse.spmatrix, Series, DataFrame]

daf.typing.unions.Known(*args, **kwargs)

Any 1D/2D data type that daf knows about.

Due to numpy.ndarray type annotation limitations, we can’t use mypy to ensure this is actually 1D/2D data.

alias of Union[ndarray, _fake_sparse.spmatrix, Series, DataFrame]

daf.typing.unions.is_known(data: Any) TypeGuard[Known][source]

Assert that some data is Known (and actually 1D/2D data), and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.be_known(data: Any) Union[ndarray, _fake_sparse.spmatrix, Series, DataFrame][source]

Assert that some data is Known (and actually 1D/2D data), and return it as such for mypy.

daf.typing.unions.Known1D(*args, **kwargs)

Any 1D data type that daf knows about.

Due to numpy.ndarray type annotation limitations, we can’t use mypy to ensure this is actually 1D data.

alias of Union[ndarray, Series]

daf.typing.unions.is_known1d(data: Any) TypeGuard[Known1D][source]

Assert that some data is Known1D (and actually 1D data).

daf.typing.unions.be_known1d(data: Any) Union[ndarray, Series][source]

Assert that some data is Known1D, and return it as such for mypy.

daf.typing.unions.Known2D(*args, **kwargs)

Any 2D data type that daf knows about.

Due to numpy.ndarray type annotation limitations, we can’t use mypy to ensure this is actually 2D data.

alias of Union[ndarray, _fake_sparse.spmatrix, DataFrame]

daf.typing.unions.is_known2d(data: Any) TypeGuard[Known2D][source]

Assert that some data is Known2D (and actually 2D data).

daf.typing.unions.be_known2d(data: Any) Union[_vectors.Vector, Series, _dense.DenseInRows, SparseInRows, FrameInRows, _dense.DenseInColumns, SparseInColumns, FrameInColumns][source]

Assert that some data is Known2D (and actually 2D data), and return it as such for mypy.

daf.typing.unions.Proper(*args, **kwargs)

Any “proper” 1D/2D data type that daf fully supports.

Such data need not be is_optimal.

alias of Union[_vectors.Vector, Series, _dense.DenseInRows, SparseInRows, FrameInRows, _dense.DenseInColumns, SparseInColumns, FrameInColumns]

daf.typing.unions.is_proper(data: Any, *, dtype: Optional[_dtypes.DTypes] = None) TypeGuard[Proper][source]

Assert that some data is Proper, optionally only of some dtype.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.be_proper(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None) Union[_vectors.Vector, Series, _dense.DenseInRows, SparseInRows, FrameInRows, _dense.DenseInColumns, SparseInColumns, FrameInColumns][source]

Assert that some data is Proper, optionally only of some dtype, and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.Proper1D(*args, **kwargs)

Any “proper” 1D data type that daf fully supports.

alias of Union[_vectors.Vector, Series]

daf.typing.unions.is_proper1d(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, size: Optional[int] = None) TypeGuard[Proper1D][source]

Assert that some data is Proper1D,, optionally only of some dtype, optionally only of some size.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.be_proper1d(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, size: Optional[int] = None) Union[_vectors.Vector, Series][source]

Assert that some data is Proper1D, optionally only of some dtype, optionally only of some size, and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.Proper2D(*args, **kwargs)

Any “proper” 2D data type that daf fully supports.

alias of Union[_dense.DenseInRows, SparseInRows, FrameInRows, _dense.DenseInColumns, SparseInColumns, FrameInColumns]

daf.typing.unions.is_proper2d(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None, layout: Optional[_layouts.AnyMajor] = None) TypeGuard[Proper2D][source]

Assert that some data is Proper2D, optionally only of some dtype, optionally only of some shape, optionally optionally only of a specific layout.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.be_proper2d(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None, layout: Optional[AnyMajor] = None) Union[_dense.DenseInRows, SparseInRows, FrameInRows, _dense.DenseInColumns, SparseInColumns, FrameInColumns][source]

Assert that some data is Proper2D, optionally only of some dtype, optionally only of some shape, optionally optionally only of a specific layout, and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.ProperInRows(*args, **kwargs)

Any “proper” ROW_MAJOR 2D data type that daf fully supports.

alias of Union[_dense.DenseInRows, SparseInRows, FrameInRows]

daf.typing.unions.is_proper_in_rows(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None) TypeGuard[ProperInRows][source]

Assert that some data is ProperInRows.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.be_proper_in_rows(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None) Union[_dense.DenseInRows, SparseInRows, FrameInRows][source]

Assert that some data is ProperInRows, optionally only of some dtype, optionally only of some shape, and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.ProperInColumns(*args, **kwargs)

Any “proper” COLUMN_MAJOR 2D data type that daf fully supports.

alias of Union[_dense.DenseInColumns, SparseInColumns, FrameInColumns]

daf.typing.unions.is_proper_in_columns(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None) TypeGuard[ProperInColumns][source]

Assert that some data is ProperInColumns, optionally only of some dtype, optionally only of some shape.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.unions.be_proper_in_columns(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None) Union[_dense.DenseInColumns, SparseInColumns, FrameInColumns][source]

Assert that some data is ProperInColumns, optionally only of some dtype, optionally only of some shape, and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.