pola-rs/polars · error
activate 'propagate_nans'
Error message
activate 'propagate_nans'
What it means
This panic is raised by spearman_rank_corr when the polars Python package was compiled without the 'propagate_nans' feature enabled. The Rust binding only contains the real implementation behind #[cfg(feature = "propagate_nans")]; without it, the function unconditionally panics with a directive telling the user to activate the feature.
Solutions
- Install the official polars wheel from PyPI, which includes this feature.
- If building from source, rebuild with the propagate_nans feature enabled (cargo build with --features propagate_nans or the 'all-features' option).
- As a workaround, compute Spearman correlation via rank + pearson corr: pl.corr(a.rank(), b.rank(), method='pearson').
Example fix
# before (custom build without feature)
df.select(pl.corr('a', 'b', method='spearman', propagate_nans=True))
# after: rank-then-pearson workaround, or reinstall official wheel
pip install --upgrade --force-reinstall polars
df.select(pl.corr('a', 'b', method='pearson').fill_nan(None)) # after manual rank Defensive patterns
Strategy: validation
Validate before calling
import polars as pl assert 'propagate_nans' in getattr(pl, '_features', getattr(pl.build_info(), 'features', [])) if hasattr(pl, 'build_info') else True # or feature-check at runtime: import polars; assert 'propagate_nans' in str(polars.build_info()), 'propagate_nans feature required'
Type guard
def supports_propagate_nans():
import polars
try:
return 'propagate_nans' in polars.build_info()['features']
except Exception:
return True Try / catch
try:
corr = pl.corr('a', 'b', method='spearman', propagate_nans=True)
except BaseException as e:
if 'propagate_nans' in str(e):
corr = pl.corr(pl.col('a').rank(), pl.col('b').rank(), method='pearson')
else:
raise Prevention
- Prefer official PyPI wheels over custom builds.
- Record required cargo features in your build scripts.
- Pin polars versions in deployment environments.
When it happens
Trigger: Calling pl.spearman_rank_corr (or the corresponding expression function) on a polars build installed without the propagate_nans cargo feature.
Common situations: Using a minimal/custom-compiled polars build (e.g. from source with a reduced feature set) or an environment where the binary was built without this feature; more common when building polars from source or using alternative distribution channels.
Related errors
- activate 'binary_encoding' feature
- activate dtype-categorical to convert dictionary arrays
- activate 'object' feature
- activate 'timezones' feature
- data type must be FixedSizeList
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/a89409fcc039390c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-python/src/functions/lazy.rs:586
let mut value = value.inner;
let n = n.inner;
if let Some(dtype) = dtype {
value = value.cast(dtype.0);
}
dsl::repeat(value, n).into()
}
#[pyfunction]
pub fn spearman_rank_corr(a: PyExpr, b: PyExpr, propagate_nans: bool) -> PyExpr {
#[cfg(feature = "propagate_nans")]
{
dsl::spearman_rank_corr(a.inner, b.inner, propagate_nans).into()
}
#[cfg(not(feature = "propagate_nans"))]
{
panic!("activate 'propagate_nans'")
}
}
#[pyfunction]
#[cfg(feature = "sql")]
pub fn sql_expr(sql: &str) -> PyResult<PyExpr> {
let expr = polars::sql::sql_expr(sql).map_err(PyPolarsErr::from)?;
Ok(expr.into())
}
View on GitHub (pinned to fe841f959e)