Repository: pola-rs/polars
File: crates/polars-ops/src/chunked_array/binary/namespace.rs (Rust)

Code before:
                                &arrow_data_type,
                                is_little_endian,
                            )
                        }).collect()
                    }
                })
            },
            #[cfg(feature = "dtype-array")]
            PhysicalType::FixedSizeList => {
                // We do the conversion for Arrays using a linear version of the dtype,
                // and then later reshape into the correct size.
                let linear_dtype = if let Some(ref shape) = dtype.get_shape() {
                    &DataType::Array(Box::new(dtype.leaf_dtype().clone()), shape.iter().product())
                } else {
                    dtype
                };
                let arrow_data_type = linear_dtype.to_arrow(CompatLevel::newest());

                let leaf_dtype = dtype.leaf_dtype();
                let leaf_physical_type = leaf_dtype
                    .to_arrow(CompatLevel::newest())
                    .to_physical_type();
                polars_ensure!(
                    dtype.byte_size().is_some() && leaf_physical_type.is_primitive(),
                    InvalidOperation:
                    "unsupported data type in from_buffer. Only numerical types are allowed in arrays."
                );
                let PhysicalType::Primitive(primitive_type) = leaf_physical_type else {
                    panic!("Shouldn't ever be reached.")
                };
                let element_size = leaf_dtype.byte_size().unwrap();

                let result: Vec<ArrayRef> = with_match_primitive_type!(primitive_type, |$T| {
                    unsafe {
                        ca.chunks().iter().map(|chunk| {
                            cast_binview_to_array_primitive_dyn::<$T>(
                                &**chunk,
                                &arrow_data_type,
                                is_little_endian,
                                element_size
                            )
                        }).collect::<Result<Vec<ArrayRef>, _>>()
                    }
                })?;
                if let Some(shape) = dtype.get_shape() {
                    let mut dimensions: Vec<ReshapeDimension> = shape
                        .iter()
                        .map(|&v| ReshapeDimension::new(v as i64))
                        .collect();
                    dimensions.insert(0, ReshapeDimension::Infer);
                    result

Review comment (suggestion):
This should also print which dtypes the user attempted to reinterpret from/to. (`cannot reinterpret from {:?} to {:?}`)


Code after:
                            )
                        }).collect()
                    }
                })
            },
            #[cfg(feature = "dtype-array")]
            DataType::Array(inner_dtype, array_width)
                if inner_dtype.is_primitive_numeric() || inner_dtype.is_temporal() =>
            {
                let inner_dtype = inner_dtype.to_physical();
                let result: Vec<ArrayRef> = with_match_physical_numeric_polars_type!(inner_dtype, |$T| {
                    unsafe {
                        ca.chunks().iter().map(|chunk| {
                            binview_to_fixed_size_list_dyn::<<$T as PolarsNumericType>::Native>(
                                &**chunk,
                                *array_width,
                                is_little_endian
                            )
                        }).collect::<Result<Vec<ArrayRef>, _>>()
                    }
                })?;
                Ok(result)
            },
            _ => Err(
                polars_err!(InvalidOperation: "unsupported data type {:?} in reinterpret. Only numeric or temporal types, or Arrays of those, are allowed.", dtype),
            ),
        }
    }
}

impl BinaryNameSpaceImpl for BinaryChunked {}