pola-rs/polars · error
activate 'object' feature
Error message
activate 'object' feature
What it means
new_object constructs a polars Series from arbitrary Python objects, but that capability only exists when the polars binary was compiled with the 'object' feature. Without it, the function panics with a directive to activate the feature. Official PyPI wheels include this feature; custom/minimal builds may not.
Solutions
- Install the official polars wheel from PyPI, which has the object feature enabled.
- If building from source, enable the feature: cargo build/pip install with --features object (or the polars['all'] extras).
- Avoid pl.Object: store data in supported dtypes, or keep Python objects outside the DataFrame.
- Consider storing complex objects as serialized JSON/Binary columns instead.
Example fix
# before (custom build without object feature)
s = pl.Series('objs', [MyClass(), MyClass()], dtype=pl.Object)
# after
pip install --upgrade --force-reinstall polars
s = pl.Series('objs', [obj.to_dict() for obj in objs], dtype=pl.Struct) # or reinstall official wheel Defensive patterns
Strategy: validation
Validate before calling
import polars
assert 'object' in str(polars.build_info()) or hasattr(polars, 'Object'), \
'polars build lacks object feature' Type guard
def object_dtype_supported():
import polars
return 'object' in str(getattr(polars, 'build_info', lambda: '')()), Try / catch
try:
s = pl.Series('a', values, dtype=pl.Object)
except BaseException as e:
if 'object' in str(e) and 'feature' in str(e):
s = pl.Series('a', [json.dumps(v, default=str) for v in values]) # serialize instead
else:
raise Prevention
- Use official polars wheels where the object feature is enabled.
- Prefer Struct/JSON columns over pl.Object.
- Avoid map_elements/apply paths that materialize Python objects on slim builds.
When it happens
Trigger: Creating a Series with dtype=pl.Object (e.g. pl.Series('a', [some_python_object], dtype=pl.Object)) on a polars build compiled without the object feature; also hit by certain .map_elements / apply paths that fall back to object construction.
Common situations: Building polars from source with a reduced feature set; using slim/alternative builds or embedded environments (e.g. some WASM or minimal distributions) without the object feature.
Related errors
- activate object
- activate 'binary_encoding' feature
- activate 'propagate_nans'
- should be hashable
- a non-HTTPS workspace_url was given
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/8adf97c8a1dff3e4.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-python/src/series/construction.rs:374
#[staticmethod]
#[pyo3(signature = (name, values, strict, dtype))]
fn new_array(
name: &str,
values: &Bound<PyAny>,
strict: bool,
dtype: Wrap<DataType>,
) -> PyResult<Self> {
Self::new_from_any_values_and_dtype(name, values, dtype, strict)
}
#[staticmethod]
pub fn new_object(py: Python<'_>, name: &str, values: Vec<ObjectValue>, _strict: bool) -> Self {
#[cfg(feature = "object")]
{
PySeries::from(series_from_objects(py, name.into(), values))
}
#[cfg(not(feature = "object"))]
panic!("activate 'object' feature")
}
#[staticmethod]
fn new_null(name: &str, values: &Bound<PyAny>, _strict: bool) -> PyResult<Self> {
let len = values.len()?;
Ok(Series::new_null(name.into(), len).into())
}
#[staticmethod]
fn from_arrow(name: &str, array: &Bound<PyAny>) -> PyResult<Self> {
let arr = array_to_rust(array)?;
// Compute first. The physical conversion retains offsets so the flag remains valid.
let fast_explode = arr
.as_any()
.downcast_ref::<LargeListArray>()
.is_some_and(|a| a.offsets().as_slice().windows(2).all(|w| w[0] != w[1]));
View on GitHub (pinned to fe841f959e)