pola-rs/polars · error
to_list not implemented for unknown
Error message
to_list not implemented for unknown
What it means
to_list_recursive converts a Series into nested Python objects. DataType::Unknown represents a dtype that could not be resolved (typically an unresolved lazy/dynamic dtype or plugin output), and there is no Python representation for it, so the code panics with 'to_list not implemented for unknown'.
Solutions
- Resolve the dtype before to_list: cast the column to a concrete dtype, e.g. df['col'].cast(pl.String).to_list().
- Fix the producing expression so it declares a concrete output_dtype (set return_dtype in map_elements or the plugin function).
- Upgrade polars and any polars plugins to matching versions to avoid Unknown dtypes from deserialization.
- Use .to_pandas() or .to_numpy() only after the dtype is resolved; inspect df.schema to find the Unknown column.
Example fix
# before df['mystery'].to_list() # dtype is Unknown -> panic # after print(df.schema) # find Unknown column print(df['mystery'].cast(pl.String).to_list())
Defensive patterns
Strategy: validation
Validate before calling
unknown_cols = [n for n, dt in df.schema.items() if dt == pl.Unknown or str(dt) == 'unknown']
assert not unknown_cols, f'unresolved dtypes in: {unknown_cols}' Type guard
def has_resolved_dtypes(df):
return all(str(dt) != 'unknown' for dt in df.schema.values()) Try / catch
try:
vals = df['col'].to_list()
except BaseException as e:
if 'not implemented for unknown' in str(e):
vals = df['col'].cast(pl.String).to_list()
else:
raise Prevention
- Inspect df.schema after collect() on lazy frames with plugins.
- Always specify return_dtype/output_dtype in map_elements and plugin calls.
- Keep polars and plugin versions in sync.
When it happens
Trigger: Calling Series.to_list() on a column whose dtype is DataType::Unknown — commonly produced by plugin expression outputs, failed dtype resolution in lazy frames, or experimental dtype paths.
Common situations: After collect() of a lazy frame using plugin/functions whose return dtype was not resolved; deserialized or cached lazy plans with unresolved dtypes; polars version mismatches between client and plugin.
Related errors
- python function failed
- activate dtype
- activate object
- cannot compare datetime.datetime to Series of type
- cannot construct PySeries for type
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/cb61066a40b480be.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-python/src/series/export.rs:161
iter: RepeatN<Option<u8>>,
n: usize,
}
impl Iterator for NullIter {
type Item = Option<u8>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next()
}
fn size_hint(&self) -> (usize, Option<usize>) {
(self.n, Some(self.n))
}
}
impl ExactSizeIterator for NullIter {}
PyList::new(py, NullIter { iter, n })?
},
DataType::Unknown(_) => {
panic!("to_list not implemented for unknown")
},
DataType::BinaryOffset => {
unreachable!()
},
DataType::Map(_, _) => {
let ca = series.map().map_err(PyPolarsErr::from)?;
PyList::new(py, ca.any_value_iter().map(Wrap))?
},
DataType::Extension(_, _) => {
return to_list_recursive(py, series.ext().unwrap().storage());
},
};
Ok(pylist.into_any())
}
to_list_recursive(py, series)
}
View on GitHub (pinned to fe841f959e)