bayesline.api.equity.AsyncReportAccessorApi#

class bayesline.api.equity.AsyncReportAccessorApi#

Abstract base class for report accessor APIs.

This class extends BaseReportAccessorApi with additional abstract methods for getting level values and data from portfolio reports.

__init__()#

Methods

__init__()

get_data(path, *[, expand, pivot_cols, ...])

Get data for the specified path.

get_data_as_task(path, *[, expand, ...])

get_level_values([levels, include_totals, ...])

Get level values for the specified levels.

is_path_valid(path_levels, *[, expand])

Check if a path is valid.

validate_path(path_levels[, expand])

Validate a path and expand tuple.

with_scenario_settings(scenario_settings, *)

Return a new accessor with the given scenario settings applied.

Attributes

axes

Get the axes configuration for the report.

axes_hashes

Get content hashes of the axis dimensions.

axis_lookup

Get the axis lookup mapping.

dimension_descriptors

Get the semantic descriptors of the dimensions.

identifier

The identifier of the report accessor.

metric_cols

Get the metric column names for the report.

metric_descriptors

Get the semantic descriptors of the metric columns.

pivot_cols

Get the pivot column names for the report.

scenario_settings

Get the scenario settings for the report.

scenario_types

Get the scenario types for the report.

abstract property identifier: int | str#

The identifier of the report accessor.

This identifier can be used to reload the underlying report accessor. The identifier is ephemeral, and should only be used for short-lived sessions, and not persisted over time.

Returns#

int | str

The identifier of the report accessor.

abstractmethod async get_level_values(levels: tuple[str, ...] = (), include_totals: bool = False, filters: list[tuple[str, str, Any] | Sequence[tuple[str, str, Any]]] | None = None) → DataFrame#

Get level values for the specified levels.

Parameters#

levelstuple[str, …], default=()

The levels to get values for.

include_totalsbool, default=False

Whether to include totals in the results.

filtersDNFFilterExpressions | None, default=None

Optional filters to apply.

Returns#

pl.DataFrame

A DataFrame containing the level values.

abstractmethod async get_data(path: list[tuple[str, str | int | bool]], *, expand: tuple[str, ...] = (), pivot_cols: tuple[str, ...] = (), value_cols: tuple[str, ...] = (), filters: list[tuple[str, str, Any] | Sequence[tuple[str, str, Any]]] | None = None, pivot_total: bool = False, absent: Literal['drop', 'null', 'keep'] = 'keep') → DataFrame#

Get data for the specified path.

Parameters#

pathlist[tuple[str, str | int | bool]]

The path to get data for. Entries pin specific values along the report’s dimensions and are AND-ed together as filters.

expandtuple[str, …], default=()

The expand tuple for the path.

pivot_colstuple[str, …], default=()

The columns to pivot on.

value_colstuple[str, …], default=()

The value columns.

filtersDNFFilterExpressions | None, default=None

Optional filters to apply.

pivot_totalbool, default=False

Whether to include pivot totals.

absentLiteral[“drop”, “null”, “keep”], default=”keep”

How to treat cells the report never saw (e.g. an asset a drilled-into portfolio never held, or a report’s degenerate warmup date). "keep" leaves them as-is (the pre-existing behaviour, a rendered 0); "null" blanks the absent cells to NaN but keeps every row; "drop" removes a row when all of its cells are absent.

Returns#

pl.DataFrame

A DataFrame containing the requested data.

abstractmethod async get_data_as_task(path: list[tuple[str, str | int | bool]], *, expand: tuple[str, ...] = (), pivot_cols: tuple[str, ...] = (), value_cols: tuple[str, ...] = (), filters: list[tuple[str, str, Any] | Sequence[tuple[str, str, Any]]] | None = None, pivot_total: bool = False, absent: Literal['drop', 'null', 'keep'] = 'keep') → AsyncTask[DataFrame]#
abstractmethod async with_scenario_settings(scenario_settings: Annotated[PortfolioHoldingsScenario | BasketFactorScenario, FieldInfo(annotation=NoneType, required=True, discriminator='type')] | Sequence[Annotated[PortfolioHoldingsScenario | BasketFactorScenario, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, name: str | None = None) → Self#

Return a new accessor with the given scenario settings applied.

Parameters#

scenario_settingsAnyScenarioSettings | Sequence[AnyScenarioSettings]

The scenario settings to apply.

namestr | None, default=None

Keep the scenario under this name, scoped to this report. The call returns once the scenario is computed, and every later query of the returned accessor, in any session, reuses it. The same name with the same settings returns the same accessor at once; the same name with different settings replaces what the name held. Without a name the scenario is computed on the first query, and later queries with the same settings, in any session, reuse it.

Returns#

Self

A new accessor with the scenario settings applied.