{"record":{"id":"5cc120cfa23aa837","repo":"pola-rs/polars","slug":"take-not-supported-for-data-type","errorCode":null,"errorMessage":"Take not supported for data type {:?}","messagePattern":"Take not supported for data type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-compute/src/gather/mod.rs","lineNumber":85,"sourceCode":"            structure::take_unchecked(array, indices).boxed()\n        },\n        LargeList => {\n            let array = values.as_any().downcast_ref().unwrap();\n            Box::new(list::take_unchecked::<i64>(array, indices))\n        },\n        FixedSizeList => {\n            let array = values.as_any().downcast_ref().unwrap();\n            fixed_size_list::take_unchecked(array, indices)\n        },\n        BinaryView => {\n            let array: &BinaryViewArray = values.as_any().downcast_ref().unwrap();\n            binview::take_binview_unchecked(array, indices).boxed()\n        },\n        Utf8View => {\n            let array: &Utf8ViewArray = values.as_any().downcast_ref().unwrap();\n            binview::take_binview_unchecked(array, indices).boxed()\n        },\n        t => unimplemented!(\"Take not supported for data type {:?}\", t),\n    }\n}\n\n/// Naive default implementation\nunsafe fn take_unchecked_impl_generic<T>(\n    values: &T,\n    indices: &IdxArr,\n    new_null_func: &dyn Fn(ArrowDataType, usize) -> T,\n) -> T\nwhere\n    T: StaticArray + ArrayFromIterDtype<std::option::Option<Box<dyn array::Array>>>,\n{\n    if values.null_count() == values.len() || indices.null_count() == indices.len() {\n        return new_null_func(values.dtype().clone(), indices.len());\n    }\n\n    match (indices.has_nulls(), values.has_nulls()) {\n        (true, true) => {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-compute/src/gather/mod.rs#L67-L103","documentation":"polars-compute's gather kernel take_unchecked dispatches on physical type and supports Null, Boolean, Primitive, LargeBinary, Struct, LargeList, FixedSizeList, BinaryView and Utf8View. Every other physical type — legacy Utf8/Binary (i32 offsets), LargeUtf8, List (i32), Map, Union, Dictionary — hits t => unimplemented!(\"Take not supported for data type {:?}\", t) at crates/polars-compute/src/gather/mod.rs:85 and panics. It is an unsafe fn whose documented contract covers bounds but not dtypes, so the restriction is implicit and unenforced.","triggerScenarios":"take_unchecked(values, indices) on e.g. a Utf8 (i32) string column, dictionary-encoded array, or List (i32) column that was not cast first — typically via polars take/gather/filter fast paths or direct calls into polars_compute::gather.","commonSituations":"Legacy IPC/Parquet string data in Utf8 form; interop with engines emitting dictionary-encoded or 32-bit list columns; performance code that skipped the up-front cast to Utf8View/LargeList.","solutions":["Cast string/binary columns to Utf8View/BinaryView and lists to LargeList before gathering","Use a checked take API that returns a Result and validates the dtype","Guard values.dtype().to_physical_type() against the supported set before the unsafe call","Upstream: route missing types through take_unchecked_impl_generic or add dedicated arms"],"exampleFix":"// before\nlet out = unsafe { take_unchecked(utf8_values, &indices) }; // panics: Take not supported for Utf8\n\n// after\nlet values = cast(utf8_values, &ArrowDataType::Utf8View)?;\nlet out = unsafe { take_unchecked(values.as_ref(), &indices) };","handlingStrategy":"type-guard","validationCode":"use polars_arrow::datatypes::PhysicalType;\nfn take_supported(dtype: &ArrowDataType) -> bool {\n    matches!(\n        dtype.to_physical_type(),\n        PhysicalType::Null | PhysicalType::Boolean | PhysicalType::Primitive(_)\n            | PhysicalType::LargeBinary | PhysicalType::Struct | PhysicalType::LargeList\n            | PhysicalType::FixedSizeList | PhysicalType::BinaryView | PhysicalType::Utf8View\n    )\n}\npolars_ensure!(take_supported(values.dtype()),\n    InvalidOperation: \"take not supported for {:?}; cast to Utf8View/BinaryView/LargeList first\", values.dtype());","typeGuard":"fn take_supported(dtype: &ArrowDataType) -> bool {\n    use polars_arrow::datatypes::PhysicalType::*;\n    matches!(\n        dtype.to_physical_type(),\n        Null | Boolean | Primitive(_) | LargeBinary | Struct | LargeList\n            | FixedSizeList | BinaryView | Utf8View\n    )\n}","tryCatchPattern":"let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| unsafe { take_unchecked(values, &indices) }));\nlet out = match res {\n    Ok(v) => v,\n    Err(_) => polars_bail!(ComputeError: \"take_unchecked panicked: unsupported dtype {:?}\", values.dtype()),\n};","preventionTips":["Normalize strings to Utf8View and lists to LargeList at ingestion so gather fast paths always hit supported arms","Never call the unsafe take_unchecked without first asserting the physical type","Keep a dtype support matrix for polars-compute kernels and enforce it in one shared validator"],"tags":["rust","polars-compute","take","gather","dtype","panic"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}