Dataset#
- class dataset.dataset_object.DatasetObject(path, **kwargs)[source]#
Bases:
ABCBase class for a tabular dataset and its feature metadata.
A dataset is created in a mutable state holding a raw, non-encoded, non-scaled dataframe (including the target column). Preprocessing steps mutate it through
snapshot()/update(). Oncefreeze()is called the object becomes immutable and the read interface (get(),ordered_features(),__len__(),__getitem__()) becomes available while the mutation interface is locked. This freeze/mutable state machine prevents recourse methods and evaluations from accidentally mutating finalized data.- Parameters:
path (str)
- raw_feature_type#
Maps each feature name to its semantic type (e.g.
"continuous","categorical").
- raw_feature_mutability#
Maps each feature name to whether it may be changed by a method.
- raw_feature_actionability#
Maps each feature name to its allowed direction of change.
- snapshot()[source]#
Return a deep copy of the current raw dataframe.
Only available while the dataset is mutable. Preprocessing steps should edit this copy and write it back with
update().- Returns:
A deep copy of the underlying dataframe.
- Return type:
- Raises:
RuntimeError – If the dataset is frozen.
- update(flag, value, df=None)[source]#
Set an attribute (and optionally swap the dataframe) on a mutable dataset.
- Parameters:
flag (str) – Name of the attribute to set. Commonly a boolean preprocessing flag (to guard against double application) or a metadata key.
value (object) – Value to store; deep-copied before assignment.
df (pandas.DataFrame, optional) – If provided, replaces the underlying dataframe (deep-copied).
- Returns:
Trueon success.- Return type:
- Raises:
RuntimeError – If the dataset is frozen.
ValueError – If
flagisNone.
- attr(flag)[source]#
Return a deep copy of a public attribute (flag or metadata).
- Parameters:
flag (str) – Public attribute name. Names starting with
_are forbidden.- Returns:
Deep copy of the stored attribute value.
- Return type:
- Raises:
AttributeError – If
flagis protected or unknown.
- get(target=False)[source]#
Return the feature columns, or the target column.
Only available once the dataset is frozen.
- Parameters:
target (bool, default False) – If
Falsereturn all feature columns (target excluded). IfTruereturn a single-column dataframe with the target.- Returns:
A deep copy of the requested columns.
- Return type:
- Raises:
RuntimeError – If the dataset is not frozen.
KeyError – If the target column is missing.
- __getitem__(key)[source]#
Index a frozen dataset by row (int/slice) or column name (str).