ReferenceData
Data
Typed datasets: the data objects discovery and inference read. Import from ergodic.data.
Each shape embeds a column Schema (continuous, categorical, ordinal,
datetime, or excluded) and shares the accessors on Dataset. The shapes
are tabular, time-series, panel, and hierarchical time-series; the event log
follows.
Build a dataset with tabular(), timeseries(), panel(), or
hts(), each of which takes a pandas or polars dataframe, a dict of columns,
or a numpy array.
Also exported from ergodic: Dataset, EventLog, HierarchicalTSData, Hierarchy, Ordinal, PanelData, Schema, SchemaInferenceWarning, TabularData, TimeSeriesData, VariableType, event_log, hts, panel, tabular, timeseries.
ColumnType#
class ColumnType(
name: str,
kind: VariableType,
categories: tuple[Any, ...] | None = None,
inferred: bool = True,
) -> None
The type of one column: its kind, and the categories when it is discrete.
| Field | Type | Default |
|---|---|---|
name |
str |
required |
kind |
VariableType |
required |
categories |
tuple[Any, ...] | None |
None |
inferred |
bool |
True |
ColumnType.ordered#
property ColumnType.ordered: bool
Whether the categories have an order (the column is ordinal).
ColumnType.is_continuous#
property ColumnType.is_continuous: bool
Whether the column is continuous.
ColumnType.is_categorical#
property ColumnType.is_categorical: bool
Whether the column is categorical (unordered).
ColumnType.is_ordinal#
property ColumnType.is_ordinal: bool
Whether the column is ordinal.
ColumnType.is_datetime#
property ColumnType.is_datetime: bool
Whether the column holds timestamps.
ColumnType.is_excluded#
property ColumnType.is_excluded: bool
Whether the column is excluded from modeling.
ColumnType.is_discrete#
property ColumnType.is_discrete: bool
Categorical or ordinal: backed by a finite set of categories.
ColumnType.cardinality#
property ColumnType.cardinality: int | None
The number of categories, or None when the column has none.
ColumnType.is_binary#
property ColumnType.is_binary: bool
Whether the column is discrete with exactly two categories.
Dataset#
class Dataset(
schema: Schema,
n_rows: int,
_store: Mapping[str, npt.NDArray[Any]],
) -> None
A typed column store. Built through the shape factories, not directly.
| Field | Type | Default |
|---|---|---|
schema |
Schema |
required |
n_rows |
int |
required |
Dataset.names#
property Dataset.names: tuple[str, ...]
The column names, in schema order (index and excluded columns included).
Dataset.n_columns#
property Dataset.n_columns: int
The number of columns, index and excluded columns included.
Dataset.shape#
property Dataset.shape: tuple[int, int]
(n_rows, n_columns).
Dataset.index_columns#
property Dataset.index_columns: tuple[str, ...]
Columns that index the rows (time, entity, case), not modeled variables.
Dataset.variables#
property Dataset.variables: tuple[str, ...]
Column names the algorithms see: not the excluded ones, not the index.
Dataset.column#
def Dataset.column(name: str) -> npt.NDArray[Any]
A read-only copy of one column's raw values.
Dataset.codes#
def Dataset.codes(name: str) -> npt.NDArray[np.int64]
Integer category codes for a categorical or ordinal column, -1 for missing.
A non-missing value outside the column's categories raises a ValueError.
Dataset.categories#
def Dataset.categories(name: str) -> tuple[Any, ...] | None
Return the categories of a discrete column, or None for any other column.
| Raises | Description |
|---|---|
KeyError |
The column is not in the dataset. |
Dataset.matrix#
def Dataset.matrix(
names: Sequence[str] | None = None,
) -> npt.NDArray[np.float64]
A float matrix of the named columns. Discrete columns become their codes, and a missing value (an NA category or NaT) becomes NaN.
Dataset.to_numpy#
def Dataset.to_numpy() -> npt.NDArray[np.float64]
Return the modeled variables as a float matrix, one column per variable.
The same as matrix() with no names: index and excluded columns are left
out, discrete columns become their codes, and a missing value becomes NaN.
Dataset.to_pandas#
def Dataset.to_pandas() -> pd.DataFrame
Return every column as a pandas.DataFrame, with the raw values.
Index and excluded columns are included. Needs pandas.
Dataset.missing#
def Dataset.missing() -> dict[str, int]
Missing-value count per column.
Dataset.has_missing#
property Dataset.has_missing: bool
Whether any column has at least one missing value.
Dataset.dropna#
def Dataset.dropna() -> Self
Drop every row with a missing value in any column.
Dataset.take#
def Dataset.take(rows: Sequence[int] | npt.NDArray[np.int64]) -> Self
A new dataset with the rows at the given positions, in the given order.
Positions may repeat (a bootstrap resample) and may be negative (Python indexing). Row identity is all this knows about; shapes with row semantics (time series, panel) keep their index columns but it is the caller's job to resample in a way their structure survives.
Dataset.select#
def Dataset.select(names: Iterable[str]) -> Self
A new dataset with the named columns, plus any index columns, in order.
Dataset.with_type#
def Dataset.with_type(
name: str,
kind: VariableType | str | Ordinal,
categories: Sequence[Any] | None = None,
) -> Self
A new dataset with name retyped, categories read from data when needed.
Dataset.exclude#
def Dataset.exclude(*names: str) -> Self
A new dataset with the named columns marked excluded.
Dataset.alignment#
def Dataset.alignment(graph: MixedGraph) -> list[str]
Where the variables and the graph's nodes disagree, empty when they match.
Dataset.aligns_with#
def Dataset.aligns_with(graph: MixedGraph) -> bool
True when the variables are exactly the graph's nodes.
EventLog#
class EventLog(
schema: Schema,
n_rows: int,
_store: Mapping[str, npt.NDArray[Any]],
case: str,
activity: str,
timestamp: str,
) -> None
Events keyed by case, activity, and timestamp; one row per event.
| Field | Type | Default |
|---|---|---|
schema |
Schema |
required |
n_rows |
int |
required |
case |
str |
required |
activity |
str |
required |
timestamp |
str |
required |
EventLog.index_columns#
property EventLog.index_columns: tuple[str, ...]
Columns that index the rows (time, entity, case), not modeled variables.
EventLog.cases#
property EventLog.cases: tuple[Any, ...]
The distinct case identifiers, sorted.
EventLog.n_cases#
property EventLog.n_cases: int
The number of distinct cases.
EventLog.activities#
property EventLog.activities: tuple[str, ...]
The distinct activity names, sorted.
EventLog.n_activities#
property EventLog.n_activities: int
The number of distinct activities.
EventLog.traces#
def EventLog.traces() -> dict[Any, tuple[str, ...]]
The ordered activity sequence per case.
EventLog.variants#
def EventLog.variants() -> Counter[tuple[str, ...]]
How many cases follow each distinct activity sequence.
EventLog.directly_follows#
def EventLog.directly_follows() -> Counter[tuple[str, str]]
Counts of each (a, b) where b immediately follows a in a case.
EventLog.names#
property EventLog.names: tuple[str, ...]
The column names, in schema order (index and excluded columns included).
EventLog.n_columns#
property EventLog.n_columns: int
The number of columns, index and excluded columns included.
EventLog.shape#
property EventLog.shape: tuple[int, int]
(n_rows, n_columns).
EventLog.variables#
property EventLog.variables: tuple[str, ...]
Column names the algorithms see: not the excluded ones, not the index.
EventLog.column#
def EventLog.column(name: str) -> npt.NDArray[Any]
A read-only copy of one column's raw values.
EventLog.codes#
def EventLog.codes(name: str) -> npt.NDArray[np.int64]
Integer category codes for a categorical or ordinal column, -1 for missing.
A non-missing value outside the column's categories raises a ValueError.
EventLog.categories#
def EventLog.categories(name: str) -> tuple[Any, ...] | None
Return the categories of a discrete column, or None for any other column.
| Raises | Description |
|---|---|
KeyError |
The column is not in the dataset. |
EventLog.matrix#
def EventLog.matrix(
names: Sequence[str] | None = None,
) -> npt.NDArray[np.float64]
A float matrix of the named columns. Discrete columns become their codes, and a missing value (an NA category or NaT) becomes NaN.
EventLog.to_numpy#
def EventLog.to_numpy() -> npt.NDArray[np.float64]
Return the modeled variables as a float matrix, one column per variable.
The same as matrix() with no names: index and excluded columns are left
out, discrete columns become their codes, and a missing value becomes NaN.
EventLog.to_pandas#
def EventLog.to_pandas() -> pd.DataFrame
Return every column as a pandas.DataFrame, with the raw values.
Index and excluded columns are included. Needs pandas.
EventLog.missing#
def EventLog.missing() -> dict[str, int]
Missing-value count per column.
EventLog.has_missing#
property EventLog.has_missing: bool
Whether any column has at least one missing value.
EventLog.dropna#
def EventLog.dropna() -> Self
Drop every row with a missing value in any column.
EventLog.take#
def EventLog.take(rows: Sequence[int] | npt.NDArray[np.int64]) -> Self
A new dataset with the rows at the given positions, in the given order.
Positions may repeat (a bootstrap resample) and may be negative (Python indexing). Row identity is all this knows about; shapes with row semantics (time series, panel) keep their index columns but it is the caller's job to resample in a way their structure survives.
EventLog.select#
def EventLog.select(names: Iterable[str]) -> Self
A new dataset with the named columns, plus any index columns, in order.
EventLog.with_type#
def EventLog.with_type(
name: str,
kind: VariableType | str | Ordinal,
categories: Sequence[Any] | None = None,
) -> Self
A new dataset with name retyped, categories read from data when needed.
EventLog.exclude#
def EventLog.exclude(*names: str) -> Self
A new dataset with the named columns marked excluded.
EventLog.alignment#
def EventLog.alignment(graph: MixedGraph) -> list[str]
Where the variables and the graph's nodes disagree, empty when they match.
EventLog.aligns_with#
def EventLog.aligns_with(graph: MixedGraph) -> bool
True when the variables are exactly the graph's nodes.
HierarchicalTSData#
class HierarchicalTSData(
schema: Schema,
n_rows: int,
_store: Mapping[str, npt.NDArray[Any]],
time: str,
freq: str | None,
hierarchy: Hierarchy,
) -> None
A time-series whose columns form an aggregation hierarchy.
| Field | Type | Default |
|---|---|---|
schema |
Schema |
required |
n_rows |
int |
required |
time |
str |
required |
freq |
str | None |
required |
hierarchy |
Hierarchy |
required |
HierarchicalTSData.aggregate#
def HierarchicalTSData.aggregate(node: str) -> npt.NDArray[np.float64]
Build a node's series from its direct children, recursively.
A child contributes its own column when it has one, else its aggregate,
and the parent is the sum or mean of those child series. This is the same
definition coherence() checks, so the two cannot disagree.
HierarchicalTSData.coherence#
def HierarchicalTSData.coherence(
rtol: float = 1e-05,
atol: float = 1e-08,
) -> list[str]
Where a present parent column does not match aggregate() of its children.
HierarchicalTSData.is_coherent#
def HierarchicalTSData.is_coherent(
rtol: float = 1e-05,
atol: float = 1e-08,
) -> bool
True when every present parent equals the aggregate of its children.
HierarchicalTSData.index_columns#
property HierarchicalTSData.index_columns: tuple[str, ...]
Columns that index the rows (time, entity, case), not modeled variables.
HierarchicalTSData.times#
property HierarchicalTSData.times: npt.NDArray[Any]
The time index, in ascending order.
HierarchicalTSData.names#
property HierarchicalTSData.names: tuple[str, ...]
The column names, in schema order (index and excluded columns included).
HierarchicalTSData.n_columns#
property HierarchicalTSData.n_columns: int
The number of columns, index and excluded columns included.
HierarchicalTSData.shape#
property HierarchicalTSData.shape: tuple[int, int]
(n_rows, n_columns).
HierarchicalTSData.variables#
property HierarchicalTSData.variables: tuple[str, ...]
Column names the algorithms see: not the excluded ones, not the index.
HierarchicalTSData.column#
def HierarchicalTSData.column(name: str) -> npt.NDArray[Any]
A read-only copy of one column's raw values.
HierarchicalTSData.codes#
def HierarchicalTSData.codes(name: str) -> npt.NDArray[np.int64]
Integer category codes for a categorical or ordinal column, -1 for missing.
A non-missing value outside the column's categories raises a ValueError.
HierarchicalTSData.categories#
def HierarchicalTSData.categories(name: str) -> tuple[Any, ...] | None
Return the categories of a discrete column, or None for any other column.
| Raises | Description |
|---|---|
KeyError |
The column is not in the dataset. |
HierarchicalTSData.matrix#
def HierarchicalTSData.matrix(
names: Sequence[str] | None = None,
) -> npt.NDArray[np.float64]
A float matrix of the named columns. Discrete columns become their codes, and a missing value (an NA category or NaT) becomes NaN.
HierarchicalTSData.to_numpy#
def HierarchicalTSData.to_numpy() -> npt.NDArray[np.float64]
Return the modeled variables as a float matrix, one column per variable.
The same as matrix() with no names: index and excluded columns are left
out, discrete columns become their codes, and a missing value becomes NaN.
HierarchicalTSData.to_pandas#
def HierarchicalTSData.to_pandas() -> pd.DataFrame
Return every column as a pandas.DataFrame, with the raw values.
Index and excluded columns are included. Needs pandas.
HierarchicalTSData.missing#
def HierarchicalTSData.missing() -> dict[str, int]
Missing-value count per column.
HierarchicalTSData.has_missing#
property HierarchicalTSData.has_missing: bool
Whether any column has at least one missing value.
HierarchicalTSData.dropna#
def HierarchicalTSData.dropna() -> Self
Drop every row with a missing value in any column.
HierarchicalTSData.take#
def HierarchicalTSData.take(
rows: Sequence[int] | npt.NDArray[np.int64],
) -> Self
A new dataset with the rows at the given positions, in the given order.
Positions may repeat (a bootstrap resample) and may be negative (Python indexing). Row identity is all this knows about; shapes with row semantics (time series, panel) keep their index columns but it is the caller's job to resample in a way their structure survives.
HierarchicalTSData.select#
def HierarchicalTSData.select(names: Iterable[str]) -> Self
A new dataset with the named columns, plus any index columns, in order.
HierarchicalTSData.with_type#
def HierarchicalTSData.with_type(
name: str,
kind: VariableType | str | Ordinal,
categories: Sequence[Any] | None = None,
) -> Self
A new dataset with name retyped, categories read from data when needed.
HierarchicalTSData.exclude#
def HierarchicalTSData.exclude(*names: str) -> Self
A new dataset with the named columns marked excluded.
HierarchicalTSData.alignment#
def HierarchicalTSData.alignment(graph: MixedGraph) -> list[str]
Where the variables and the graph's nodes disagree, empty when they match.
HierarchicalTSData.aligns_with#
def HierarchicalTSData.aligns_with(graph: MixedGraph) -> bool
True when the variables are exactly the graph's nodes.
Hierarchy#
class Hierarchy(
edges: frozenset[tuple[str, str]],
aggregation: str = 'sum',
) -> None
A tree of named series, with edges running parent to child, and an aggregation rule.
| Field | Type | Default |
|---|---|---|
edges |
frozenset[tuple[str, str]] |
required |
aggregation |
str |
'sum' |
Hierarchy.tree#
classmethod Hierarchy.tree(
adjacency: Mapping[str, Iterable[str]],
aggregation: str = 'sum',
) -> Hierarchy
Build from a parent-to-children mapping, for example {"total": ["a", "b"]}.
Hierarchy.children_of#
def Hierarchy.children_of(node: str) -> tuple[str, ...]
Return the children of node, sorted; empty for a leaf.
Raises ValueError when node is not in the hierarchy.
Hierarchy.parent_of#
def Hierarchy.parent_of(node: str) -> str | None
Return the parent of node, or None for a root.
Raises ValueError when node is not in the hierarchy.
Hierarchy.is_leaf#
def Hierarchy.is_leaf(node: str) -> bool
Return True when node has no children.
Raises ValueError when node is not in the hierarchy.
Hierarchy.roots#
property Hierarchy.roots: tuple[str, ...]
Nodes with no parent.
Hierarchy.leaves#
property Hierarchy.leaves: tuple[str, ...]
Nodes with no children: the base series.
Hierarchy.internal_nodes#
property Hierarchy.internal_nodes: tuple[str, ...]
Nodes with children: the aggregates.
Hierarchy.leaf_descendants#
def Hierarchy.leaf_descendants(node: str) -> tuple[str, ...]
The base series that aggregate up to node (node itself when it is a leaf).
Hierarchy.levels#
def Hierarchy.levels() -> dict[str, int]
Depth of each node, with roots at 0.
Ordinal#
class Ordinal(levels: Sequence[Any]) -> None
Mark a column ordinal, listing its categories in increasing order.
Use it in a type override: types={"stage": Ordinal(["I", "II", "III"])}.
| Field | Type | Default |
|---|---|---|
levels |
Sequence[Any] |
required |
PanelData#
class PanelData(
schema: Schema,
n_rows: int,
_store: Mapping[str, npt.NDArray[Any]],
entity: str,
time: str,
freq: str | None = None,
) -> None
Entities observed over time, keyed by a unique (entity, time) pair.
| Field | Type | Default |
|---|---|---|
schema |
Schema |
required |
n_rows |
int |
required |
entity |
str |
required |
time |
str |
required |
freq |
str | None |
None |
PanelData.index_columns#
property PanelData.index_columns: tuple[str, ...]
Columns that index the rows (time, entity, case), not modeled variables.
PanelData.entities#
property PanelData.entities: tuple[Any, ...]
The distinct entity identifiers, sorted.
PanelData.periods#
property PanelData.periods: tuple[Any, ...]
The distinct time values, sorted.
PanelData.n_entities#
property PanelData.n_entities: int
The number of distinct entities.
PanelData.n_periods#
property PanelData.n_periods: int
The number of distinct time values.
PanelData.is_balanced#
property PanelData.is_balanced: bool
True when every entity is seen in every period (a full grid).
PanelData.time_invariant#
def PanelData.time_invariant() -> tuple[str, ...]
Variables whose value never changes within an entity.
PanelData.names#
property PanelData.names: tuple[str, ...]
The column names, in schema order (index and excluded columns included).
PanelData.n_columns#
property PanelData.n_columns: int
The number of columns, index and excluded columns included.
PanelData.shape#
property PanelData.shape: tuple[int, int]
(n_rows, n_columns).
PanelData.variables#
property PanelData.variables: tuple[str, ...]
Column names the algorithms see: not the excluded ones, not the index.
PanelData.column#
def PanelData.column(name: str) -> npt.NDArray[Any]
A read-only copy of one column's raw values.
PanelData.codes#
def PanelData.codes(name: str) -> npt.NDArray[np.int64]
Integer category codes for a categorical or ordinal column, -1 for missing.
A non-missing value outside the column's categories raises a ValueError.
PanelData.categories#
def PanelData.categories(name: str) -> tuple[Any, ...] | None
Return the categories of a discrete column, or None for any other column.
| Raises | Description |
|---|---|
KeyError |
The column is not in the dataset. |
PanelData.matrix#
def PanelData.matrix(
names: Sequence[str] | None = None,
) -> npt.NDArray[np.float64]
A float matrix of the named columns. Discrete columns become their codes, and a missing value (an NA category or NaT) becomes NaN.
PanelData.to_numpy#
def PanelData.to_numpy() -> npt.NDArray[np.float64]
Return the modeled variables as a float matrix, one column per variable.
The same as matrix() with no names: index and excluded columns are left
out, discrete columns become their codes, and a missing value becomes NaN.
PanelData.to_pandas#
def PanelData.to_pandas() -> pd.DataFrame
Return every column as a pandas.DataFrame, with the raw values.
Index and excluded columns are included. Needs pandas.
PanelData.missing#
def PanelData.missing() -> dict[str, int]
Missing-value count per column.
PanelData.has_missing#
property PanelData.has_missing: bool
Whether any column has at least one missing value.
PanelData.dropna#
def PanelData.dropna() -> Self
Drop every row with a missing value in any column.
PanelData.take#
def PanelData.take(rows: Sequence[int] | npt.NDArray[np.int64]) -> Self
A new dataset with the rows at the given positions, in the given order.
Positions may repeat (a bootstrap resample) and may be negative (Python indexing). Row identity is all this knows about; shapes with row semantics (time series, panel) keep their index columns but it is the caller's job to resample in a way their structure survives.
PanelData.select#
def PanelData.select(names: Iterable[str]) -> Self
A new dataset with the named columns, plus any index columns, in order.
PanelData.with_type#
def PanelData.with_type(
name: str,
kind: VariableType | str | Ordinal,
categories: Sequence[Any] | None = None,
) -> Self
A new dataset with name retyped, categories read from data when needed.
PanelData.exclude#
def PanelData.exclude(*names: str) -> Self
A new dataset with the named columns marked excluded.
PanelData.alignment#
def PanelData.alignment(graph: MixedGraph) -> list[str]
Where the variables and the graph's nodes disagree, empty when they match.
PanelData.aligns_with#
def PanelData.aligns_with(graph: MixedGraph) -> bool
True when the variables are exactly the graph's nodes.
Schema#
class Schema(columns: tuple[ColumnType, ...]) -> None
An ordered set of column types, queryable by name and by kind.
| Field | Type | Default |
|---|---|---|
columns |
tuple[ColumnType, ...] |
required |
Schema.get#
def Schema.get(name: str) -> ColumnType | None
Return the type of column name, or None when there is no such column.
Schema.names#
property Schema.names: tuple[str, ...]
The column names, in order.
Schema.of_kind#
def Schema.of_kind(kind: VariableType) -> tuple[str, ...]
Return the names of the columns of one kind, in schema order.
Schema.continuous#
property Schema.continuous: tuple[str, ...]
The names of the continuous columns.
Schema.categorical#
property Schema.categorical: tuple[str, ...]
The names of the categorical columns (ordinal columns are not included).
Schema.ordinal#
property Schema.ordinal: tuple[str, ...]
The names of the ordinal columns.
Schema.datetime#
property Schema.datetime: tuple[str, ...]
The names of the datetime columns.
Schema.excluded#
property Schema.excluded: tuple[str, ...]
The names of the excluded columns.
Schema.discrete#
property Schema.discrete: tuple[str, ...]
Categorical and ordinal columns together.
Schema.variables#
property Schema.variables: tuple[str, ...]
Every column the algorithms see: all but the excluded ones.
Schema.with_type#
def Schema.with_type(
name: str,
kind: VariableType | str | Ordinal,
categories: Sequence[Any] | None = None,
) -> Schema
Return a new schema with name retyped. Marks the column user-set.
SchemaInferenceWarning#
A column type was guessed from ambiguous data (for example integer levels).
TabularData#
class TabularData(
schema: Schema,
n_rows: int,
_store: Mapping[str, npt.NDArray[Any]],
) -> None
Cross-sectional data: rows are independent units, with no index column.
| Field | Type | Default |
|---|---|---|
schema |
Schema |
required |
n_rows |
int |
required |
TabularData.names#
property TabularData.names: tuple[str, ...]
The column names, in schema order (index and excluded columns included).
TabularData.n_columns#
property TabularData.n_columns: int
The number of columns, index and excluded columns included.
TabularData.shape#
property TabularData.shape: tuple[int, int]
(n_rows, n_columns).
TabularData.index_columns#
property TabularData.index_columns: tuple[str, ...]
Columns that index the rows (time, entity, case), not modeled variables.
TabularData.variables#
property TabularData.variables: tuple[str, ...]
Column names the algorithms see: not the excluded ones, not the index.
TabularData.column#
def TabularData.column(name: str) -> npt.NDArray[Any]
A read-only copy of one column's raw values.
TabularData.codes#
def TabularData.codes(name: str) -> npt.NDArray[np.int64]
Integer category codes for a categorical or ordinal column, -1 for missing.
A non-missing value outside the column's categories raises a ValueError.
TabularData.categories#
def TabularData.categories(name: str) -> tuple[Any, ...] | None
Return the categories of a discrete column, or None for any other column.
| Raises | Description |
|---|---|
KeyError |
The column is not in the dataset. |
TabularData.matrix#
def TabularData.matrix(
names: Sequence[str] | None = None,
) -> npt.NDArray[np.float64]
A float matrix of the named columns. Discrete columns become their codes, and a missing value (an NA category or NaT) becomes NaN.
TabularData.to_numpy#
def TabularData.to_numpy() -> npt.NDArray[np.float64]
Return the modeled variables as a float matrix, one column per variable.
The same as matrix() with no names: index and excluded columns are left
out, discrete columns become their codes, and a missing value becomes NaN.
TabularData.to_pandas#
def TabularData.to_pandas() -> pd.DataFrame
Return every column as a pandas.DataFrame, with the raw values.
Index and excluded columns are included. Needs pandas.
TabularData.missing#
def TabularData.missing() -> dict[str, int]
Missing-value count per column.
TabularData.has_missing#
property TabularData.has_missing: bool
Whether any column has at least one missing value.
TabularData.dropna#
def TabularData.dropna() -> Self
Drop every row with a missing value in any column.
TabularData.take#
def TabularData.take(rows: Sequence[int] | npt.NDArray[np.int64]) -> Self
A new dataset with the rows at the given positions, in the given order.
Positions may repeat (a bootstrap resample) and may be negative (Python indexing). Row identity is all this knows about; shapes with row semantics (time series, panel) keep their index columns but it is the caller's job to resample in a way their structure survives.
TabularData.select#
def TabularData.select(names: Iterable[str]) -> Self
A new dataset with the named columns, plus any index columns, in order.
TabularData.with_type#
def TabularData.with_type(
name: str,
kind: VariableType | str | Ordinal,
categories: Sequence[Any] | None = None,
) -> Self
A new dataset with name retyped, categories read from data when needed.
TabularData.exclude#
def TabularData.exclude(*names: str) -> Self
A new dataset with the named columns marked excluded.
TabularData.alignment#
def TabularData.alignment(graph: MixedGraph) -> list[str]
Where the variables and the graph's nodes disagree, empty when they match.
TabularData.aligns_with#
def TabularData.aligns_with(graph: MixedGraph) -> bool
True when the variables are exactly the graph's nodes.
TimeSeriesData#
class TimeSeriesData(
schema: Schema,
n_rows: int,
_store: Mapping[str, npt.NDArray[Any]],
time: str,
freq: str | None,
) -> None
Series ordered by a time column, with an optional sampling frequency.
| Field | Type | Default |
|---|---|---|
schema |
Schema |
required |
n_rows |
int |
required |
time |
str |
required |
freq |
str | None |
required |
TimeSeriesData.index_columns#
property TimeSeriesData.index_columns: tuple[str, ...]
Columns that index the rows (time, entity, case), not modeled variables.
TimeSeriesData.times#
property TimeSeriesData.times: npt.NDArray[Any]
The time index, in ascending order.
TimeSeriesData.names#
property TimeSeriesData.names: tuple[str, ...]
The column names, in schema order (index and excluded columns included).
TimeSeriesData.n_columns#
property TimeSeriesData.n_columns: int
The number of columns, index and excluded columns included.
TimeSeriesData.shape#
property TimeSeriesData.shape: tuple[int, int]
(n_rows, n_columns).
TimeSeriesData.variables#
property TimeSeriesData.variables: tuple[str, ...]
Column names the algorithms see: not the excluded ones, not the index.
TimeSeriesData.column#
def TimeSeriesData.column(name: str) -> npt.NDArray[Any]
A read-only copy of one column's raw values.
TimeSeriesData.codes#
def TimeSeriesData.codes(name: str) -> npt.NDArray[np.int64]
Integer category codes for a categorical or ordinal column, -1 for missing.
A non-missing value outside the column's categories raises a ValueError.
TimeSeriesData.categories#
def TimeSeriesData.categories(name: str) -> tuple[Any, ...] | None
Return the categories of a discrete column, or None for any other column.
| Raises | Description |
|---|---|
KeyError |
The column is not in the dataset. |
TimeSeriesData.matrix#
def TimeSeriesData.matrix(
names: Sequence[str] | None = None,
) -> npt.NDArray[np.float64]
A float matrix of the named columns. Discrete columns become their codes, and a missing value (an NA category or NaT) becomes NaN.
TimeSeriesData.to_numpy#
def TimeSeriesData.to_numpy() -> npt.NDArray[np.float64]
Return the modeled variables as a float matrix, one column per variable.
The same as matrix() with no names: index and excluded columns are left
out, discrete columns become their codes, and a missing value becomes NaN.
TimeSeriesData.to_pandas#
def TimeSeriesData.to_pandas() -> pd.DataFrame
Return every column as a pandas.DataFrame, with the raw values.
Index and excluded columns are included. Needs pandas.
TimeSeriesData.missing#
def TimeSeriesData.missing() -> dict[str, int]
Missing-value count per column.
TimeSeriesData.has_missing#
property TimeSeriesData.has_missing: bool
Whether any column has at least one missing value.
TimeSeriesData.dropna#
def TimeSeriesData.dropna() -> Self
Drop every row with a missing value in any column.
TimeSeriesData.take#
def TimeSeriesData.take(rows: Sequence[int] | npt.NDArray[np.int64]) -> Self
A new dataset with the rows at the given positions, in the given order.
Positions may repeat (a bootstrap resample) and may be negative (Python indexing). Row identity is all this knows about; shapes with row semantics (time series, panel) keep their index columns but it is the caller's job to resample in a way their structure survives.
TimeSeriesData.select#
def TimeSeriesData.select(names: Iterable[str]) -> Self
A new dataset with the named columns, plus any index columns, in order.
TimeSeriesData.with_type#
def TimeSeriesData.with_type(
name: str,
kind: VariableType | str | Ordinal,
categories: Sequence[Any] | None = None,
) -> Self
A new dataset with name retyped, categories read from data when needed.
TimeSeriesData.exclude#
def TimeSeriesData.exclude(*names: str) -> Self
A new dataset with the named columns marked excluded.
TimeSeriesData.alignment#
def TimeSeriesData.alignment(graph: MixedGraph) -> list[str]
Where the variables and the graph's nodes disagree, empty when they match.
TimeSeriesData.aligns_with#
def TimeSeriesData.aligns_with(graph: MixedGraph) -> bool
True when the variables are exactly the graph's nodes.
VariableType#
class VariableType(enum.Enum)
How a column is measured, which decides the methods that apply to it.
| Member | Value |
|---|---|
CONTINUOUS |
'continuous' |
CATEGORICAL |
'categorical' |
ORDINAL |
'ordinal' |
DATETIME |
'datetime' |
EXCLUDED |
'excluded' |
event_log#
def event_log(
data: Any,
*,
case: str,
activity: str,
timestamp: str,
columns: Sequence[str] | None = None,
types: Mapping[str, VariableType | str | Ordinal] | None = None,
exclude: Iterable[str] | None = None,
categorical_threshold: int = 10,
) -> EventLog
Build an EventLog, grouped by case and ordered by timestamp.
hts#
def hts(
data: Any,
*,
time: str,
hierarchy: Hierarchy | Mapping[str, Iterable[str]],
freq: str | None = None,
columns: Sequence[str] | None = None,
types: Mapping[str, VariableType | str | Ordinal] | None = None,
exclude: Iterable[str] | None = None,
categorical_threshold: int = 10,
) -> HierarchicalTSData
Build a HierarchicalTSData from series columns and a hierarchy.
infer_schema#
def infer_schema(
store: Mapping[str, npt.NDArray[Any]],
*,
n_rows: int,
declared: Mapping[str, ColumnType] | None = None,
overrides: Mapping[str, VariableType | str | Ordinal] | None = None,
exclude: Iterable[str] | None = None,
categorical_threshold: int = 10,
) -> Schema
Build a schema from columns: user overrides beat source-declared beat inferred.
panel#
def panel(
data: Any,
*,
entity: str,
time: str,
freq: str | None = None,
columns: Sequence[str] | None = None,
types: Mapping[str, VariableType | str | Ordinal] | None = None,
exclude: Iterable[str] | None = None,
categorical_threshold: int = 10,
) -> PanelData
Build a PanelData, keyed and sorted by (entity, time).
tabular#
def tabular(
data: Any,
*,
columns: Sequence[str] | None = None,
types: Mapping[str, VariableType | str | Ordinal] | None = None,
exclude: Iterable[str] | None = None,
categorical_threshold: int = 10,
) -> TabularData
Build a TabularData from a dataframe, a dict of columns, or an array.
| Parameter | Description |
|---|---|
data |
A pandas or polars dataframe, a mapping of name to column, or a 2-D numpy array (name the columns with columns). |
columns |
Column names, used when data is a bare numpy array. |
types |
Per-column type overrides, for example {"age": "continuous", "stage": Ordinal(["I", "II", "III"])}. |
exclude |
Columns to mark excluded, so they are kept but not treated as variables (identifiers, free text). |
categorical_threshold |
Integer columns with at most this many distinct values are inferred categorical, with a warning. |
timeseries#
def timeseries(
data: Any,
*,
time: str,
freq: str | None = None,
columns: Sequence[str] | None = None,
types: Mapping[str, VariableType | str | Ordinal] | None = None,
exclude: Iterable[str] | None = None,
categorical_threshold: int = 10,
) -> TimeSeriesData
Build a TimeSeriesData, sorting rows by the time column.
The time column is typed from its data (datetime, else continuous) unless you override it, so an integer step index is not mistaken for a category.