bayesline.api.equity.RiskDatasetLoaderApi#
- class bayesline.api.equity.RiskDatasetLoaderApi#
API for loading and managing risk datasets.
This class provides functionality for loading, creating, and managing risk datasets through a registry-based approach.
self.settingsis a registry view over the discriminated unionAnyRiskDatasetSettings— both reference-basedDerivedRiskDatasetSettingsand rootRootRiskDatasetSettingsare addressable through the same handle.- __init__()#
Methods
__init__()create_dataset(name, settings)Create a new dataset with the given name and settings.
create_dataset_as_task(name, settings)create_or_replace_dataset(name, settings)Create a new dataset or replace an existing one.
delete_dataset(name)Delete the given dataset.
delete_dataset_if_exists(name)Delete the given dataset if it exists.
get_dataset_names(*[, mode])Get the names of all available datasets.
get_dataset_status(name)Return the status of a single dataset.
list_riskdatasets([name, df])List all available risk datasets.
load(ref_or_settings, *args, **kwargs)Load an API instance from settings or reference.
validate(settings)Validate
settingsagainst the menu for its dataset.Attributes
settingsGet the settings registry.
- abstract get_dataset_names(*, mode: Literal['System', 'User'] | None = None) dict[str, Literal['ready', 'data_stale', 'needs_update', 'not_ready', 'corrupt']]#
Get the names of all available datasets.
Datasets owned by the current user are exposed under both their email-qualified name (
alice@example.com/MyDS) and a bare alias (MyDS), mapping to the same status. This is intentional — it lets callers look up a dataset by either form against the returned dict (the status-fetch helpers incalendar,universe,exposures,portfoliosrely on this). Callers iteratinglen(...),sorted(...), or building counts from the result should treat the dual-key entries as one logical dataset.Parameters#
- modeLiteral[“System”, “User”] | None, default=None
System: only system wide datasets (available to all users and provided by the system). User: only user specific datasets (available to the current user). None: all datasets (system wide and user specific).
Returns#
- dict[str, DatasetStatus]
The names of all available datasets and their status. “ready” means the dataset is ready to use. “data_stale” means the dataset is ready to use but newer data is available. “needs_update” means local data needs to be computed/updated. “not_ready” means the reference dataset is not in a usable state. “corrupt” means the underlying settings are corrupted and need to be repaired.
- get_dataset_status(name: str) Literal['ready', 'data_stale', 'needs_update', 'not_ready', 'corrupt']#
Return the status of a single dataset.
Defaults to indexing
get_dataset_names(); implementations may override to resolve a single dataset’s status without computing the status of every dataset.Parameters#
- namestr
Name of the dataset (bare alias or email-qualified).
Returns#
- DatasetStatus
The status of the dataset. See
get_dataset_names()for the meaning of each value.
Raises#
- KeyError
If
nameis not a known dataset.
- abstract list_riskdatasets(name: str | None = None, *, df: bool = False) list[RiskDatasetMetadata] | DataFrame#
List all available risk datasets.
Parameters#
- namestr | None, default=None
The name of the dataset to filter by. If not given, all datasets are returned.
- dfbool, default=False
If True, return a polars DataFrame instead of a list of metadata objects.
Returns#
- list[RiskDatasetMetadata] | pl.DataFrame
The metadata of all available datasets, either as a list of objects or as a DataFrame depending on the df parameter.
- create_or_replace_dataset(name: str, settings: Annotated[DerivedRiskDatasetSettings | RootRiskDatasetSettings, Discriminator(discriminator=kind, custom_error_type=None, custom_error_message=None, custom_error_context=None)]) RiskDatasetApi#
Create a new dataset or replace an existing one.
Parameters#
- namestr
The name of the dataset to create or replace.
- settingsAnyRiskDatasetSettings
The settings for the dataset. Pass
DerivedRiskDatasetSettingsfor a reference-based dataset; passRootRiskDatasetSettingsfor a root dataset built from upload sources.
Returns#
- RiskDatasetApi
The API for the created or replaced dataset.
- abstract create_dataset(name: str, settings: Annotated[DerivedRiskDatasetSettings | RootRiskDatasetSettings, Discriminator(discriminator=kind, custom_error_type=None, custom_error_message=None, custom_error_context=None)]) RiskDatasetApi#
Create a new dataset with the given name and settings.
Parameters#
- namestr
The name of the dataset to create.
- settingsAnyRiskDatasetSettings
The settings for the dataset to create. Pass
DerivedRiskDatasetSettingsfor a reference-based dataset; passRootRiskDatasetSettingsfor a root dataset built from upload sources. Dispatch is byisinstanceof the settings type.
Raises#
- DatasetError
If a dataset with the given name already exists or if the settings are otherwise invalid.
Returns#
- RiskDatasetApi
The API of the newly created dataset.
- abstract create_dataset_as_task(name: str, settings: Annotated[DerivedRiskDatasetSettings | RootRiskDatasetSettings, Discriminator(discriminator=kind, custom_error_type=None, custom_error_message=None, custom_error_context=None)]) Task[RiskDatasetApi]#