omnipy.components.general.tasks
General tasks for splitting, importing, and creating datasets and models.
| FUNCTION | DESCRIPTION |
|---|---|
concat_all_vals_in_datasets_as_args |
Concatenate all value from positional datasets. |
concat_all_vals_in_datasets_as_kwargs |
Concatenate all values from keyword datasets. |
create_dataset_from_args |
Create a dataset from one or more positional payload objects. |
create_dataset_from_kwargs |
Create a dataset from named model or sub-dataset inputs. |
create_model_from_args |
Create a model from positional inputs. |
create_model_from_kwargs |
Create a model from named keyword inputs. |
import_directory |
Import files from a directory into a dataset keyed by filename stem. |
split_dataset |
Split a dataset into two datasets based on selected data-file names. |
union_all_datasets_as_args |
Union all positional datasets. |
union_all_datasets_as_kwargs |
Union all keyword datasets. |
union_all_vals_in_datasets_as_args |
Union all dataset values from positional datasets. |
union_all_vals_in_datasets_as_kwargs |
Union all dataset values from keyword datasets. |
concat_all_vals_in_datasets_as_args
concat_all_vals_in_datasets_as_args(
first_dataset: Dataset[Model[_SupportsIAddT]], *other_datasets: Dataset[Model[Any]]
) -> Model[_SupportsIAddT]
Concatenate all value from positional datasets.
Concatenation is based on a deep copy of the first value, with
consecutive concatenations through the += operator.
Source code in src/omnipy/components/general/tasks.py
concat_all_vals_in_datasets_as_kwargs
concat_all_vals_in_datasets_as_kwargs(
**datasets: Dataset[Model[_SupportsIAddT]],
) -> Model[_SupportsIAddT]
Concatenate all values from keyword datasets.
Concatenation is based on a deep copy of the first value, with
consecutive concatenations through the += operator.
Source code in src/omnipy/components/general/tasks.py
create_dataset_from_args
create_dataset_from_args(
*args: object,
dataset_cls: type[_DatasetT],
key: str | None = None,
keys: tuple[str, ...] | None = None,
) -> _DatasetT
Create a dataset from one or more positional payload objects.
With no positional inputs, an empty dataset is created. A single
positional input is forwarded as a single argument. Multiple
positional inputs are packed into the tuple normally represented by
*args before Dataset construction, allowing for key-value pairs to
be passed as positional arguments. Alternatively, the key or
keys keyword parameters can be used to specify the keys for the
datasets.
| PARAMETER | DESCRIPTION |
|---|---|
*args
|
Positional payload passed to the dataset constructor.
TYPE:
|
dataset_cls
|
Dataset class to instantiate.
TYPE:
|
key
|
Optional single key (as string) for a single dataset entry.
TYPE:
|
keys
|
Optional keys (as tuple of strings) to use for the dataset
entries. Must be of the same length as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_DatasetT
|
A dataset instance of type |
Source code in src/omnipy/components/general/tasks.py
create_dataset_from_kwargs
Create a dataset from named model or sub-dataset inputs.
| PARAMETER | DESCRIPTION |
|---|---|
dataset_cls
|
Dataset class to instantiate.
TYPE:
|
**data
|
Named dataset entries forwarded as keyword arguments to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_DatasetT
|
A dataset instance of type |
Source code in src/omnipy/components/general/tasks.py
create_model_from_args
Create a model from positional inputs.
A single positional input is forwarded unchanged. Multiple positional inputs are packed into the
tuple normally represented by *args before model construction.
| PARAMETER | DESCRIPTION |
|---|---|
*args
|
Positional payload values to turn into the model root value.
TYPE:
|
model_cls
|
Model class to instantiate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_ModelT
|
A model instance of type |
Source code in src/omnipy/components/general/tasks.py
create_model_from_kwargs
Create a model from named keyword inputs.
| PARAMETER | DESCRIPTION |
|---|---|
model_cls
|
Model class to instantiate.
TYPE:
|
**data
|
Named values forwarded as keyword arguments to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_ModelT
|
A model instance of type |
Source code in src/omnipy/components/general/tasks.py
import_directory
import_directory(
directory: str | Path,
exclude_prefixes: tuple[str, ...] = (".", "_"),
include_suffixes: tuple[str, ...] = (),
dataset_cls: type[_DatasetT] = Dataset[Model[str]],
open_func: Callable[[str], IOBase] = open,
) -> _DatasetT
Import files from a directory into a dataset keyed by filename stem.
| PARAMETER | DESCRIPTION |
|---|---|
directory
|
Directory to scan for files.
TYPE:
|
exclude_prefixes
|
Filename prefixes to skip.
TYPE:
|
include_suffixes
|
Optional filename suffixes to include.
TYPE:
|
dataset_cls
|
Dataset type to instantiate for the imported content. |
open_func
|
Callable used to open each matching file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_DatasetT
|
A dataset containing one item per imported file. |
Source code in src/omnipy/components/general/tasks.py
split_dataset
split_dataset(
dataset: Dataset[Model[object]], datafile_names_for_b: list[str]
) -> tuple[Dataset[Model[object]], Dataset[Model[object]]]
Split a dataset into two datasets based on selected data-file names.
| PARAMETER | DESCRIPTION |
|---|---|
dataset
|
Dataset to split. |
datafile_names_for_b
|
Names that should be placed in the second output dataset.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Dataset[Model[object]], Dataset[Model[object]]]
|
A tuple containing the remaining items first and the selected items second. |
Source code in src/omnipy/components/general/tasks.py
union_all_datasets_as_args
union_all_datasets_as_args(
first_dataset: _DatasetT, *other_datasets: Dataset[Model[Any]]
) -> _DatasetT
Union all positional datasets.
Union is based on a deep copy of the first dataset, with consecutive
unions through the |= operator.
Source code in src/omnipy/components/general/tasks.py
union_all_datasets_as_kwargs
Union all keyword datasets.
Union is based on a deep copy of the first dataset, with consecutive
unions through the |= operator.
Source code in src/omnipy/components/general/tasks.py
union_all_vals_in_datasets_as_args
union_all_vals_in_datasets_as_args(
first_dataset: Dataset[Model[_SupportsIOrT]], *other_datasets: Dataset[Model[Any]]
) -> Model[_SupportsIOrT]
Union all dataset values from positional datasets.
Union is based on a deep copy of the first value, with consecutive
unions through the |= operator.
Source code in src/omnipy/components/general/tasks.py
union_all_vals_in_datasets_as_kwargs
union_all_vals_in_datasets_as_kwargs(
**datasets: Dataset[Model[_SupportsIOrT]],
) -> Model[_SupportsIOrT]
Union all dataset values from keyword datasets.
Union is based on a deep copy of the first value, with consecutive
unions through the |= operator.