pola-rs/polars · error

activate feature dynamic_group_by

Error message

activate feature dynamic_group_by

What it means

The memory-engine's GroupByDynamic executor has a stub implementation when the `dynamic_group_by` cargo feature is disabled: execute() immediately panics telling the user to activate the feature. Dynamic group_by (e.g. resampling by time windows) cannot run in that build.

Solutions

  1. Enable the feature in Cargo.toml: polars = { version = "...", features = ["dynamic_group_by"] } (usually via polars = { features = ["lazy", "dynamic_group_by"] }).
  2. Use the full `polars` meta-crate with default features or `features = ["full"]`.
  3. Rewrite the operation with plain group_by + expression-based date_trunc/windowing if you must stay feature-minimal.
  4. Verify with `cargo tree -e features` that the feature actually reaches the final build.

Example fix

// before (Cargo.toml)
polars = { version = "0.46", features = ["lazy"] }
// after
polars = { version = "0.46", features = ["lazy", "dynamic_group_by"] }
Defensive patterns

Strategy: validation

Validate before calling

// build-time check: ensure the feature is enabled in Cargo.toml
// polars = { features = ["dynamic_group_by"] }
// runtime check in code that uses group_by_dynamic:
#[cfg(not(feature = "dynamic_group_by"))]
compile_error!("group_by_dynamic requires the polars 'dynamic_group_by' feature");

Prevention

When it happens

Trigger: Executing a lazy plan containing a group_by_dynamic operation (group_by_dynamic / upsample / rolling by time) against a polars build compiled without the `dynamic_group_by` feature.

Common situations: Using a minimal/default polars build (e.g. a slim Docker image or a crate depending on polars-core without the feature) and calling .group_by_dynamic() or time-based resampling; distributions that strip optional features.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/564ca96d99c0542e. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-mem-engine/src/executors/group_by_dynamic.rs:87

                *key = key.slice(offset, len)
            }
        }

        let agg_columns = evaluate_aggs(&df, &self.aggs, groups, state)?;

        let mut columns = Vec::with_capacity(agg_columns.len() + 1 + keys.len());
        columns.extend_from_slice(&keys);
        columns.push(time_key);
        columns.extend(agg_columns);

        DataFrame::new_infer_height(columns)
    }
}

impl Executor for GroupByDynamicExec {
    #[cfg(not(feature = "dynamic_group_by"))]
    fn execute(&mut self, _state: &mut ExecutionState) -> PolarsResult<DataFrame> {
        panic!("activate feature dynamic_group_by")
    }

    #[cfg(feature = "dynamic_group_by")]
    fn execute(&mut self, state: &mut ExecutionState) -> PolarsResult<DataFrame> {
        state.should_stop()?;
        #[cfg(debug_assertions)]
        {
            if state.verbose() {
                eprintln!("run GroupbyDynamicExec")
            }
        }
        let df = self.input.execute(state)?;
        self.execute_impl(state, df)
    }
}

View on GitHub (pinned to fe841f959e)