DataSource

A module for representing and managing data sources. It defines an abstract base class for data sources as well as concrete implementations with serialization and deserialization functionality.

class algomancy_data.datasource.DataClassification(*values)[source]

Bases: StrEnum

MASTER_DATA = 'master_data'
DERIVED_DATA = 'derived_data'
DUMMY_DATA = 'dummy_data'
class algomancy_data.datasource.BaseDataSource(ds_type, name=None, validation_messages=None, ds_id=None, creation_datetime=None)[source]

Bases: ABC

Base class for data sources.

This class serves as a base for defining different types of data sources. It provides basic attributes and methods to handle data source IDs, creation timestamps, names, and validation messages. It also defines abstract methods that should be implemented by derived classes to handle data serialization and derivation.

validation_messages

List of validation messages for the data source.

Type:

List[ValidationMessage] | None

property name: str
property id
property creation_datetime
is_master_data()[source]
set_to_master_data()[source]
derive(new_data_key)[source]

Creates a derived object with a given new key.

This method generates a duplicate of the current object with the same data and sets a new key for it, effectively creating a derived object with a different identifier.

Parameters:

new_data_key (str) – The new key to assign to the derived object.

Returns:

A new instance of the same class with the derived data and updated key.

Return type:

Type of the calling class

abstractmethod to_json()[source]
abstractmethod classmethod from_json(json_string)[source]
initialize_data_parameters()[source]

Declare per-scenario knobs this data source exposes.

Subclasses override to return a populated BaseParameterSet with whichever typed parameters make sense for the dataset (date range, region filter, etc.). The framework persists user-supplied values on each scenario and hands them to the algorithm via BaseAlgorithm.set_data_params before run(); the algorithm decides whether and how to act on them.

The default returns EmptyParameters() so existing data sources keep working with no edits.

Returns:

A fresh template describing this data source’s

parameters. Callers populate values via set_validated_values.

Return type:

BaseParameterSet

class algomancy_data.datasource.DataSource(ds_type, name=None, validation_messages=None, ds_id=None, creation_datetime=None)[source]

Bases: BaseDataSource

tables: dict[str, DataFrame]
to_json()[source]

Serializes the DataSource object to JSON format. This is useful for creating human-readable downloadable content in a Dash app.

Returns:

The serialized DataSource as JSON string

Return type:

str

classmethod from_json(json_string)[source]

Creates a DataSource object from serialized JSON string.

Parameters:

json_string (str) – The serialized DataSource as JSON string

Returns:

A new DataSource object with the loaded data

Return type:

BaseDataSource

add_table(name, df, logger=None)[source]
get_table(name)[source]
list_tables()[source]
to_sql_tables()[source]
from_sql_tables(tables)[source]