pola-rs/polars · error
activate dtype-categorical to convert dictionary arrays
Error message
activate dtype-categorical to convert dictionary arrays
What it means
Converting Arrow `Dictionary` arrays into Polars Series requires the `dtype-categorical` feature, since Polars represents dictionaries as Categorical/Enum dtypes. When that feature is not compiled in, `_try_from_arrow_unchecked_with_md` hits the non-feature match arm for `ArrowDataType::Dictionary` and panics, instructing the user to enable the feature.
Solutions
- Enable the feature: `polars-core = { version = "...", features = ["dtype-categorical"] }` (or add `dtype-categorical` to the polars meta-crate features).
- Re-encode the Arrow data without dictionary encoding before conversion (e.g. cast Dictionary to plain Utf8/Binary on the producer side).
- Use `arrow`-level casting to decode dictionaries into dense arrays before handing chunks to polars.
Example fix
// before (Cargo.toml)
polars = { version = "0.41", default-features = false, features = ["parquet"] }
// after
polars = { version = "0.41", default-features = false, features = ["parquet", "dtype-categorical"] } Defensive patterns
Strategy: fallback
Validate before calling
// detect dictionary-encoded arrow data before conversion let is_dict = matches!(arr.data_type(), ArrowDataType::Dictionary(_, _, _));
Type guard
fn is_dictionary_type(dt: &ArrowDataType) -> bool {
matches!(dt, ArrowDataType::Dictionary(_, _, _))
} Try / catch
// panic-based; guard before conversion:
if is_dictionary_type(chunk.data_type()) && !cfg!(feature = "dtype-categorical") {
let decoded = polars_arrow::compute::cast::cast(chunk, &ArrowDataType::LargeUtf8)?;
// convert decoded instead
} Prevention
- Enable `dtype-categorical` whenever reading Parquet/IPC from other ecosystems.
- Ask producers to disable dictionary encoding or cast dictionaries to strings upstream.
- List all dtype features explicitly when using default-features = false.
When it happens
Trigger: Reading an Arrow IPC/Feather/Parquet file containing dictionary-encoded string columns, or calling `Series::_try_from_arrow_unchecked_with_md` with Dictionary chunks, while polars-core lacks the `dtype-categorical` feature.
Common situations: Minimal-features polars installs reading dictionary-encoded Parquet produced by pyarrow; dependency trees that disable default features; cross-language data exchange where upstream tools dictionary-encode low-cardinality strings by default.
Related errors
- activate the 'dtype-struct' feature to handle struct data…
- activate 'timezones' feature
- FixedSizeListArray::arr_from_iter_with_dtype called with…
- length to fit in `usize`
- not implemented
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/7a94be055dd00fa3.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-core/src/series/from.rs:440
}).map(Some)
} else {
Ok(None)
}
}).try_collect_arr_trusted()?;
*chunk = arr_128.to(ArrowDataType::Int128).to_boxed();
}
let s = Int128Chunked::from_chunks(name, chunks)
.into_decimal_unchecked(*precision, *scale)
.into_series();
Ok(s)
})
},
ArrowDataType::Null => Ok(new_null(name, &chunks)),
#[cfg(not(feature = "dtype-categorical"))]
ArrowDataType::Dictionary(_, _, _) => {
panic!("activate dtype-categorical to convert dictionary arrays")
},
#[cfg(feature = "dtype-categorical")]
ArrowDataType::Dictionary(key_type, _, _) => {
let polars_dtype = DataType::from_arrow(chunks[0].dtype(), md);
let mut series_iter = chunks.into_iter().map(|arr| {
import_arrow_dictionary_array(name.clone(), arr, key_type, &polars_dtype)
});
let mut first = series_iter.next().unwrap()?;
for s in series_iter {
first.append_owned(s?)?;
}
Ok(first)
},
#[cfg(feature = "object")]View on GitHub (pinned to fe841f959e)