pola-rs/polars · error

horizontal_flatten not supported for data type

Error message

horizontal_flatten not supported for data type {:?}

What it means

horizontal_flatten concatenates fixed-width element arrays (e.g. list/primitive views) into flat buffers. The generic dispatch only implements a fixed set of data types (primitives, utf8 views, etc.); any other physical type hits the catch-all `unimplemented!` arm. This is a hard not-implemented panic, not a recoverable error.

Solutions

  1. Flatten only one nesting level at a time: explode/flatten the outer list first, then apply again on the inner list.
  2. Cast the element dtype to a supported type (primitive or string) before concatenating.
  3. Manually restructure the data (e.g. melt/explode) so the operation operates on flat arrays.
  4. If the dtype is legitimately needed, file/patch an implementation for that type in horizontal_flatten.

Example fix

// before
let out = concat_arr(&[list_of_lists_arr]).unwrap();
// after
let inner = list_of_lists_arr.explode().unwrap(); // flatten one level first
let out = concat_arr(&[inner_as_list_arr]).unwrap();
Defensive patterns

Strategy: validation

Validate before calling

// Rust
fn is_flattenable(dtype: &ArrowDataType) -> bool {
    matches!(dtype, ArrowDataType::LargeList(f) | ArrowDataType::List(f)
        if matches!(f.dtype(), ArrowDataType::_ _| Int8 | Int16 | Int32 | Int64 | UInt8 | UInt16 | UInt32 | UInt64 | Float32 | Float64 | Boolean))
}

Type guard

fn is_list_of_flat(dtype: &DataType) -> bool {
    matches!(dtype, DataType::List(inner) | DataType::Array(inner, _)
        if inner.is_primitive() || inner.is_string())
}

Prevention

When it happens

Trigger: Calling concat_arr / horizontal_flatten on an array whose physical type is not in the implemented match arms, e.g. a list of lists, fixed-size-lists of structs, or any other non-flattenable dtype.

Common situations: Concatenating nested list columns (list-of-lists) in Polars, or horizontally concatenating columns whose element dtype is a struct or another nested type.

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/fd49c4d687793339. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-compute/src/horizontal_flatten/mod.rs:125

                        .downcast_ref::<BinaryViewArray>()
                        .unwrap()
                        .clone()
                })
                .collect::<Vec<_>>(),
            widths,
            output_height,
            dtype,
        )),
        Utf8View => Box::new(horizontal_flatten_unchecked_impl_generic(
            &arrays
                .iter()
                .map(|x| x.as_any().downcast_ref::<Utf8ViewArray>().unwrap().clone())
                .collect::<Vec<_>>(),
            widths,
            output_height,
            dtype,
        )),
        t => unimplemented!("horizontal_flatten not supported for data type {:?}", t),
    }
}

unsafe fn horizontal_flatten_unchecked_impl_generic<T>(
    arrays: &[T],
    widths: &[usize],
    output_height: usize,
    dtype: &ArrowDataType,
) -> T
where
    T: StaticArray,
{
    assert!(!arrays.is_empty());
    assert_eq!(widths.len(), arrays.len());

    debug_assert!(widths.iter().all(|x| *x > 0));
    debug_assert!(
        arrays

View on GitHub (pinned to fe841f959e)