pola-rs/polars · error
Unsupported in row encoding
Error message
Unsupported in row encoding
What it means
get_row_encoding_context maps a DataType to its row-encoding context so columns can be sorted/joined via the row encoding. DataType::Unknown has no row-encoding representation, so the function panics rather than producing a meaningless encoding.
Solutions
- Ensure the key column has a concrete dtype before the row-encoded operation (cast to a supported dtype)
- Trace why the column is Unknown (empty frame, inference failure) and fix at construction time
- Exclude Unknown-dtype columns from sort/join keys
Example fix
// before keys.sort([unknown_col]); // panics: Unsupported in row encoding // after let col = unknown_col.cast(&DataType::Int64)?; // or fix inference keys.sort([col]);
Defensive patterns
Strategy: type-guard
Validate before calling
if matches!(key.dtype(), DataType::Unknown(_)) {
return Err("cannot row-encode key with Unknown dtype; cast it first");
} Type guard
fn row_encoding_supported(dt: &DataType) -> bool {
!matches!(dt, DataType::Unknown(_) | DataType::Object(_) | DataType::Null)
} Prevention
- Resolve dtype inference before sorting/joining
- Cast Unknown columns to concrete dtypes at frame construction
- Exclude non-encodable columns from multi-key operations
When it happens
Trigger: Using row-encoded operations (sort by multiple columns, join on keys, _get_rows_encoded*) where one of the key columns has DataType::Unknown — typically a column whose dtype could not be inferred or an unmaterialized/detached dtype.
Common situations: Constructing DataFrames with unknown dtypes (e.g. from empty or heterogeneous sources) and then sorting/joining on them; passing partially-initialized series into frame operations.
Related errors
- dtype is unknown; consider supplying data-types for all…
- {0}
- activate dtype
- activate dtype-categorical to convert dictionary arrays
- activate ' ' feature
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/624a0489062691c7.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-core/src/chunked_array/ops/row_encode.rs:113
| DataType::Null
| DataType::Time
| DataType::Date
| DataType::Datetime(_, _)
| DataType::Duration(_) => None,
#[cfg(feature = "dtype-categorical")]
DataType::Categorical(_, mapping) | DataType::Enum(_, mapping) => {
use polars_row::RowEncodingCategoricalContext;
Some(RowEncodingContext::Categorical(
RowEncodingCategoricalContext {
is_enum: matches!(dtype, DataType::Enum(_, _)),
mapping: mapping.clone(),
},
))
},
DataType::Unknown(_) => panic!("Unsupported in row encoding"),
#[cfg(feature = "object")]
DataType::Object(_) => panic!("Unsupported in row encoding"),
#[cfg(feature = "dtype-decimal")]
DataType::Decimal(precision, _) => Some(RowEncodingContext::Decimal(*precision)),
#[cfg(feature = "dtype-array")]
DataType::Array(dtype, _) => get_row_encoding_context(dtype),
DataType::List(dtype) => get_row_encoding_context(dtype),
#[cfg(feature = "dtype-struct")]
DataType::Struct(fs) => {
let mut ctxts = Vec::new();
for (i, f) in fs.iter().enumerate() {
if let Some(ctxt) = get_row_encoding_context(f.dtype()) {
ctxts.reserve(fs.len());
ctxts.extend(std::iter::repeat_n(None, i));View on GitHub (pinned to fe841f959e)