ContinuousDataset#
- class causalbase.data.ContinuousDataset(values, names)[source]#
A fully-observed dataset over continuous (real-valued) variables.
- Parameters:
- valuesnp.ndarray
Real-valued data, shape
(n_rows, n_vars). Cast tofloat64.- namesSequence[str]
Variable names, length
n_vars. Coerced to an immutabletuple[str, ...].
- Attributes:
- Raises:
- ValueError
If values is not 2-D, if names does not have exactly n_vars entries or repeats a name, or if values contains any non-finite entry (
NaNor infinity).
Notes
Non-finite values are rejected: the cumulant estimators have no notion of a missing entry.
- property n_rows#
int: Number of rows (observations) in the dataset.
- property n_vars#
int: Number of variables (columns) in the dataset.
- subset(rows)[source]#
Select a subset of rows, keeping the parent’s variable names.
- Parameters:
- rowsnumpy.ndarray
Row indices (integer array) or a boolean mask of length n_rows.
- Returns:
- ContinuousDataset
The selected rows over the same variables.
- classmethod from_pandas(df)[source]#
Build a dataset from a pandas DataFrame of numeric columns.
- Parameters:
- dfpandas.DataFrame
One column per variable, one row per observation. Column names become names.
- Returns:
- ContinuousDataset
The dataset.
- Raises:
- ValueError
If two columns share a name, or a column is non-numeric or contains a non-finite value.
- classmethod from_csv(path)[source]#
Build a dataset from a CSV file of numeric columns.
The file must have a header row of variable names followed by comma-separated numeric values.
- Parameters:
- pathstr or pathlib.Path
Path to the CSV file.
- Returns:
- ContinuousDataset
The dataset.
- Raises:
- ValueError
If any column is non-numeric, or contains a non-finite value.