cointoss.datasets¶
datasets
¶
Datasets: named, typed, long-form tables read through the frame node (ADR-0010).
A Dataset is a definition in code: a name, a description, a pydantic params model, its
columns, and a reader that turns the store and validated params into rows. DATASETS is the
registry the datasets and frame nodes on cointoss.app.CointossApp serve, so adding a
Dataset means adding one definition here, plus a store read if no existing one fits. Nothing
here touches SQL: rows come through cointoss.store (ADR-0008).
Every Dataset is long, one row per fact with a fixed column list, and every column declares a
type and a role so a client can pick axes and series without guessing from names. Rows about
an Instrument carry its survivor's instrument_id and current symbol; the rest of its
attributes are in the instruments Dataset.
woodglue serializes a node's pydantic result with model_dump(mode="json"), so a date reaches
a JSON-RPC client as an ISO string. load reads the column types datasets publishes and puts
them back on a pandas DataFrame. pandas is imported only there, from the ui extra.
An OwnedDataset holds a User's own records, the Portfolios: it is read for one
owner, the caller's User id, which the app passes and no param can set, and a Portfolio named
in its params that the owner does not hold is UnknownPortfolio, as one that does not exist.
A response holds at most ROW_CAP rows. The cap is read when a frame is read, so a test can
patch it. Over it is TooManyRows naming the matching count; there is no paging.
ROW_CAP = 250000
module-attribute
¶
The most rows one frame call returns.
DEFAULT_NAMESPACE = 'cointoss.data'
module-attribute
¶
The JSON-RPC method prefix cointoss init mounts the fragment under.
UnknownDataset
¶
InvalidParams
¶
ColumnRole
¶
Bases: StrEnum
What a column is for: the time axis, the thing a row is about, a value, or a label.
Source code in src/cointoss/datasets.py
DatasetView
¶
Bases: BaseModel
A Dataset as datasets lists it: its columns and the JSON Schema of its params.
Source code in src/cointoss/datasets.py
Dataset
dataclass
¶
Bases: _Definition[P]
A Dataset anyone with the namespace's Grant reads in full.
rows returns each row's values in columns order.
Source code in src/cointoss/datasets.py
OwnedDataset
dataclass
¶
Bases: _Definition[P]
A Dataset of one User's records, which read cannot be called without.
rows returns the owner's rows, each row's values in columns order.
Source code in src/cointoss/datasets.py
read(store, params, owner)
¶
The Dataset as owner holds it, raising TooManyRows past ROW_CAP.
load(client, name, /, *, namespace=DEFAULT_NAMESPACE, **params)
async
¶
Read a Dataset over JSON-RPC into a pandas DataFrame with its column types applied.
Async, because WoodglueClient.call is; a sync caller such as Streamlit wraps it in
asyncio.run. Calls datasets for the column types, then
frame. A date column becomes naive datetime64 at midnight and a datetime column
UTC-aware datetime64, so both chart and resample directly; a nullable int or bool
column uses pandas' nullable dtype. namespace is the method prefix the fragment is
mounted under. A JSON-RPC error raises woodglue.client.WoodglueRpcError.
Needs pandas, from the ui extra.