pola-rs/polars · error

Take not supported for data type

Error message

Take not supported for data type {:?}

What it means

`take_unchecked` in polars-compute implements the gather/take operation by matching on the array's data type. Types without a dedicated take kernel hit `t => unimplemented!("Take not supported for data type {:?}", t)`, which panics naming the dtype. Like error 60, this reflects kernel coverage gaps rather than bad input indices.

Solutions

  1. Convert the column to a supported dtype (e.g. cast to Utf8View/Primitive) before taking.
  2. Use the non-unchecked / generic take API that supports the type, or fall back to a row-wise implementation.
  3. Upgrade polars — new releases continuously add take kernel coverage; otherwise file an upstream issue for the dtype.

Example fix

// before
let out = unsafe { take_unchecked(values, indices) }; // panics for unsupported dtype
// after
let values = if is_unsupported_dtype(values.dtype()) {
    values.cast(&fallback_dtype)?
} else {
    values.clone()
};
let out = unsafe { take_unchecked(&values, indices) };
Defensive patterns

Strategy: fallback

Validate before calling

fn take_supported(dtype: &ArrowDataType) -> bool {
    matches!(
        dtype.to_physical_type(),
        ArrowDataType::Null | ArrowDataType::Boolean
            | ArrowDataType::Int8 | ArrowDataType::Int16 | ArrowDataType::Int32
            | ArrowDataType::Int64 | ArrowDataType::UInt8 | ArrowDataType::UInt16
            | ArrowDataType::UInt32 | ArrowDataType::UInt64
            | ArrowDataType::Float32 | ArrowDataType::Float64
            | ArrowDataType::Utf8 | ArrowDataType::LargeUtf8
            | ArrowDataType::Binary | ArrowDataType::LargeBinary
            | ArrowDataType::Utf8View | ArrowDataType::BinaryView
    ) // extend to cover all branches of take_unchecked
}

Try / catch

// Panics cannot be caught in stable Rust; choose the path up front:
let out = if take_supported(values.dtype()) {
    unsafe { take_unchecked(values, indices) }
} else {
    take_fallback(values, indices)? // row-wise / cast-based path
};

Prevention

When it happens

Trigger: Calling `take_unchecked(values, indices)` on an array whose `ArrowDataType` has no implemented take branch — e.g. less common dtypes (certain nested/extension types) not listed in the match.

Common situations: Generic selection/filter code paths hitting an unusual column dtype; newly added Arrow types not yet wired into the gather kernel; DataFrame ops on extension or dictionary-adjacent types.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at crates/polars-compute/src/gather/mod.rs:85

            structure::take_unchecked(array, indices).boxed()
        },
        LargeList => {
            let array = values.as_any().downcast_ref().unwrap();
            Box::new(list::take_unchecked::<i64>(array, indices))
        },
        FixedSizeList => {
            let array = values.as_any().downcast_ref().unwrap();
            fixed_size_list::take_unchecked(array, indices)
        },
        BinaryView => {
            let array: &BinaryViewArray = values.as_any().downcast_ref().unwrap();
            binview::take_binview_unchecked(array, indices).boxed()
        },
        Utf8View => {
            let array: &Utf8ViewArray = values.as_any().downcast_ref().unwrap();
            binview::take_binview_unchecked(array, indices).boxed()
        },
        t => unimplemented!("Take not supported for data type {:?}", t),
    }
}

/// Naive default implementation
unsafe fn take_unchecked_impl_generic<T>(
    values: &T,
    indices: &IdxArr,
    new_null_func: &dyn Fn(ArrowDataType, usize) -> T,
) -> T
where
    T: StaticArray + ArrayFromIterDtype<std::option::Option<Box<dyn array::Array>>>,
{
    if values.null_count() == values.len() || indices.null_count() == indices.len() {
        return new_null_func(values.dtype().clone(), indices.len());
    }

    match (indices.has_nulls(), values.has_nulls()) {
        (true, true) => {

View on GitHub (pinned to fe841f959e)