diff --git a/src/blueetl/config/analysis_model.py b/src/blueetl/config/analysis_model.py index 6b14163..8ce0482 100644 --- a/src/blueetl/config/analysis_model.py +++ b/src/blueetl/config/analysis_model.py @@ -151,6 +151,7 @@ class FeaturesConfig(BaseModel): params_product: dict[str, Any] = {} params_zip: dict[str, Any] = {} suffix: str = "" + multi_index: bool = True class SingleAnalysisConfig(BaseModel): diff --git a/src/blueetl/features.py b/src/blueetl/features.py index e3d7df6..29cc906 100644 --- a/src/blueetl/features.py +++ b/src/blueetl/features.py @@ -417,7 +417,11 @@ def _func_wrapper( # ignore the index if it's unnamed and with one level; this can be useful # for example when the returned DataFrame has a RangeIndex to be dropped drop = result_df.index.names == [None] - result_df = result_df.etl.add_conditions(conditions=key._fields, values=key, drop=drop) + if features_config.multi_index: + result_df = result_df.etl.add_conditions(conditions=key._fields, values=key, drop=drop) + else: + result_df.reset_index(drop=drop, inplace=True) + result_df.etl.insert_columns(loc=0, columns=key._fields, values=key) features_records[feature_group + features_config.suffix] = result_df return features_records diff --git a/src/blueetl/schemas/analysis_config.yaml b/src/blueetl/schemas/analysis_config.yaml index 1846af7..e54608b 100644 --- a/src/blueetl/schemas/analysis_config.yaml +++ b/src/blueetl/schemas/analysis_config.yaml @@ -444,6 +444,15 @@ $defs: A numeric suffix is automatically added when any of ``params_product`` or ``params_zip`` is specified. default: "''" type: string + multi_index: + title: MultiIndex + description: | + - If True, do not reset the index of the resulting DataFrames of features, and add the values specified in ``groupby`` to the MultiIndex. + - If False, reset the index, returning columnar DataFrames. + + The DataFrames with MultiIndex should use less memory then the columnar DataFrames, but they take more time to load and dump to disk. + type: boolean + default: "true" required: - type - groupby