coco_pipe.descriptors.io#
Descriptor-table file IO: save, load, merge, and feature-column consistency.
This is the descriptor-specific table IO layer. It builds on the generic
coco_pipe.io._serialization.read_table() primitive but owns the
descriptor concerns: the feature-column list each table carries in its
parquet metadata, loading a
descriptor table into a flat DataContainer,
and the cross-shard merge stage.
Author: Hamza Abdelhedi <hamza.abdelhedi@umontreal.ca>
Functions#
|
Write a descriptor table as |
|
The feature-column list a descriptor table carries in its |
|
Assert that a table's feature columns match the first table of its kind. |
|
Merge per-shard tables of one table kind into a single table. |
|
Load a descriptor feature table into a |
Module Contents#
- coco_pipe.descriptors.io.save_descriptor_table(df, base_path, feature_columns=None)#
Write a descriptor table as
{base_path}.parquet.The ordered feature-column list is kept in the table itself: in
df.attrs["feature_columns"], which pandas stores in the parquet file’s metadata and restores on read, so a table is one self-describing file.- Parameters:
df (pandas.DataFrame) – Table to write.
base_path (pathlib.Path | str) – Output path without suffix, e.g.
combined/sensor_recording_features.feature_columns (collections.abc.Sequence[str] | None) – Ordered list of descriptor feature-column names; defaults to the table’s own
attrs.
- Return type:
None
- coco_pipe.descriptors.io.feature_columns_of(df, source)#
The feature-column list a descriptor table carries in its
attrs.- Parameters:
df (pandas.DataFrame)
source (pathlib.Path | str)
- Return type:
- coco_pipe.descriptors.io.check_feature_column_consistency(feature_columns, accumulated, col_key, source)#
Assert that a table’s feature columns match the first table of its kind.
Intended for merging per-shard descriptor outputs: on the first call for a given col_key the column list is stored in accumulated. On every subsequent call it is compared against the stored one and a
ValueErroris raised on any mismatch, preventing a silent merge of shards produced with incompatible feature sets.- Parameters:
feature_columns (collections.abc.Sequence[str]) – Feature columns of the table being checked.
accumulated (dict[str, list[str] | None]) – Mapping of
col_key -> feature column list, mutated in place.col_key (str) – Key identifying which table kind the columns belong to (e.g.
"sensor_epoch").source (pathlib.Path | str) – The table’s path, for the error message.
- Return type:
None
- coco_pipe.descriptors.io.merge_descriptor_tables(table_paths, *, out_base_path=None)#
Merge per-shard tables of one table kind into a single table.
The cross-shard merge stage. A “table kind” is one descriptor output table, e.g.
sensor_epoch, written once per shard; this row-concatenates that kind across shards. Each shard’s feature columns are checked against the first viacheck_feature_column_consistency(), the rows are concatenated, and the combined table is optionally written viasave_descriptor_table(). Discovery, manifests, and dataset-level QC are left to the caller, which calls this once per table kind.- Parameters:
table_paths (collections.abc.Sequence[pathlib.Path | str]) – Per-shard parquet tables for one table kind, in the desired row order.
out_base_path (pathlib.Path | str | None) – Optional output path without suffix. When set, the combined table is written there via
save_descriptor_table().
- Returns:
(combined_df, feature_columns).- Return type:
- Raises:
ValueError – If table_paths is empty, a table carries no feature-column list, or a shard’s feature columns differ from the first shard.
- coco_pipe.descriptors.io.load_descriptor_table(table_path, known_families=('band', 'param', 'complexity'), condition=None, target_col=None, subjects=None, subject_col='subject', descriptor_families=None, descriptor_max_abs_value=None, drop_degenerate_columns=False, max_missing_rate=0.2, drop_constant_columns=True, constant_tol=1e-12, max_row_drop_rate=None, location_statistic=None, exclude_subfamilies=None)#
Load a descriptor feature table into a
DataContainer.- Parameters:
table_path (pathlib.Path | str)
condition (str | None)
target_col (str | None)
subjects (collections.abc.Sequence[str] | None)
subject_col (str)
descriptor_families (collections.abc.Sequence[str] | None)
descriptor_max_abs_value (float | None)
drop_degenerate_columns (bool)
max_missing_rate (float)
drop_constant_columns (bool)
constant_tol (float)
max_row_drop_rate (float | None)
location_statistic (str | None)
exclude_subfamilies (collections.abc.Sequence[str] | None)
- Return type: