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#

save_descriptor_table(df, base_path[, feature_columns])

Write a descriptor table as {base_path}.parquet.

feature_columns_of(df, source)

The feature-column list a descriptor table carries in its attrs.

check_feature_column_consistency(feature_columns, ...)

Assert that a table's feature columns match the first table of its kind.

merge_descriptor_tables(table_paths, *[, out_base_path])

Merge per-shard tables of one table kind into a single table.

load_descriptor_table(table_path[, known_families, ...])

Load a descriptor feature table into a DataContainer.

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:
Return type:

list[str]

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 ValueError is 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 via check_feature_column_consistency(), the rows are concatenated, and the combined table is optionally written via save_descriptor_table(). Discovery, manifests, and dataset-level QC are left to the caller, which calls this once per table kind.

Parameters:
Returns:

(combined_df, feature_columns).

Return type:

tuple

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:
Return type:

coco_pipe.io.structures.DataContainer