pola-rs/polars · error
not yet implemented: `apply` cannot be used with `having` pr
Error message
not yet implemented: `apply` cannot be used with `having` predicates
What it means
LazyFrame::apply (map_groups) inspects the plan and refuses to run when the frame carries HAVING predicates: group-level apply cannot be combined with a having filter, so it panics with this not-yet-implemented message. Rewrite the query to filter after the apply/agg step instead.
Source
Thrown at crates/polars-lazy/src/frame/mod.rs:2088
.collect::<Vec<_>>();
self.agg([all().as_expr().tail(n)]).explode_impl(
all() - by_name(keys.iter().cloned(), false, false),
ExplodeOptions {
empty_as_null: true,
keep_nulls: true,
},
true,
)
}
/// Apply a function over the groups as a new DataFrame.
///
/// **It is not recommended that you use this as materializing the DataFrame is very
/// expensive.**
pub fn apply(self, f: PlanCallback<DataFrame, DataFrame>, schema: SchemaRef) -> LazyFrame {
if !self.predicates.is_empty() {
panic!("not yet implemented: `apply` cannot be used with `having` predicates");
}
#[cfg(feature = "dynamic_group_by")]
let options = GroupbyOptions {
dynamic: self.dynamic_options,
rolling: self.rolling_options,
slice: None,
};
#[cfg(not(feature = "dynamic_group_by"))]
let options = GroupbyOptions { slice: None };
let lp = DslPlan::GroupBy {
input: Arc::new(self.logical_plan),
keys: self.keys,
predicates: vec![],
aggs: vec![],
apply: Some((f, schema)),View on GitHub (pinned to 5d8ebabf11)
Solutions
- Do not combine `apply` with `having` predicates; filter before or after the apply instead.
- Rewrite the query so the having condition is applied to the result of the apply step.
Defensive patterns
Strategy: fallback
When it happens
Trigger: This panic/expect fires when execution reaches an unguarded state described by: "not yet implemented: `apply` cannot be used with `having` predicates". Typical triggers: unsupported dtype or feature-gated code path reached at runtime, invalid user input or environment variable value, calling API methods in the wrong order or on mismatched types, or data (lengths, offsets, ranges) violating the function's preconditions.
Common situations: Encountered when input data or configuration does not meet the preconditions of the throwing code path ("not yet implemented: `apply` cannot be used with `having` predicates"). Common cases: missing Cargo feature flags, mismatched dtypes/lengths between arrays or series, out-of-range temporal values, malformed environment variables, or operations on unsupported/complex nested types.
AI-assisted analysis of pola-rs/polars@5d8ebabf11 (2026-08-19).
Data as JSON: /api/errors/e50610b37c900193.
Report an issue: GitHub.