pola-rs/polars · error

activate object

Error message

activate object

What it means

`get_object` in crates/polars-python/src/conversion/any_value.rs converts a Polars AnyValue::Object to a Python object. The object feature is compile-time gated; when Polars is built without the 'object' feature, any attempt to convert an Object value panics with "activate object".

Solutions

  1. Install/build polars with the object feature enabled (cargo build with --features object, or use the default pip wheel that includes it)
  2. Remove Object dtype usage; store data as supported dtypes (e.g. Struct, List, or serialized strings)
  3. Check polars.build_info()/feature flags of the installed wheel

Example fix

# before
s = pl.Series("objs", [MyClass(), MyClass()])  # polars built without object feature
# after
s = pl.Series("objs", [o.to_dict() for o in items], dtype=pl.Struct)
Defensive patterns

Strategy: type-guard

Validate before calling

import polars
assert "object" in polars.build_info()["features"], "polars built without object feature"
assert df.schema["col"] != pl.Object, "object column present but object feature unavailable"

Type guard

def object_feature_available() -> bool:
    import polars
    return "object" in polars.build_info()["features"]

Try / catch

try:
    values = df["col"].to_list()
except pl.exceptions.PanicException as e:
    if "activate object" in str(e):
        raise RuntimeError("polars built without the object feature; avoid Object dtype") from e
    raise

Prevention

When it happens

Trigger: Using Object dtype data (pl.Object, Python objects stored in a Series/DataFrame) with a polars build compiled without the 'object' feature — e.g. calling .to_pyarrow()/to_list/iteration over object columns.

Common situations: Installing a prebuilt polars wheel that excludes the object feature while user code stores arbitrary Python objects in DataFrames, or migrating from a build that had the feature to one that doesn't.

Related errors


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

Appendix: source

Thrown at crates/polars-python/src/conversion/any_value.rs:595

            let val = py_object_to_any_value(&v, strict, true, None)?;
            let dtype = val.dtype();
            keys.push(Field::new(key.as_ref().into(), dtype));
            vals.push(val)
        }
        Ok(AnyValue::StructOwned(Box::new((vals, keys))))
    }

    fn get_object(ob: &Bound<'_, PyAny>, _strict: bool) -> PyResult<AnyValue<'static>> {
        #[cfg(feature = "object")]
        {
            // This is slow, but hey don't use objects.
            let v = &ObjectValue {
                inner: ob.clone().unbind(),
            };
            Ok(AnyValue::ObjectOwned(OwnedObject(v.to_boxed())))
        }
        #[cfg(not(feature = "object"))]
        panic!("activate object")
    }

    /// Determine which conversion function to use for the given object.
    ///
    /// Note: This function is only ran if the object's type is not already in the
    /// lookup table.
    fn get_conversion_function(ob: &Bound<'_, PyAny>, allow_object: bool) -> PyResult<InitFn> {
        let py = ob.py();
        if ob.is_none() {
            Ok(get_null)
        }
        // bool must be checked before int because Python bool is an instance of int.
        else if ob.is_instance_of::<PyBool>() {
            Ok(get_bool)
        } else if ob.is_instance_of::<PyInt>() {
            Ok(get_int)
        } else if ob.is_instance_of::<PyFloat>() {
            Ok(get_float)

View on GitHub (pinned to fe841f959e)