pola-rs/polars · error
into_datetime not implemented for
Error message
into_datetime not implemented for {dt:?} What it means
Series::into_datetime panics when the series' dtype has no datetime conversion. Only Int64 (the datetime physical: epoch in the given time unit) and an existing Datetime dtype are accepted; all other dtypes hit the catch-all panic.
Solutions
- Ensure the column is Int64 epoch values in the target time unit (cast to Int64 first) before into_datetime
- Use series.strict_cast(&DataType::Datetime(timeunit, tz)) which returns a Result instead of panicking
- Convert Date to Datetime via the date namespace's cast or dt operations instead
Example fix
// before let s = series.into_datetime(TimeUnit::Ns, None); // panics for Int32 // after let s = series.cast(&DataType::Int64)?.into_datetime(TimeUnit::Ns, None);
Defensive patterns
Strategy: type-guard
Validate before calling
if !matches!(s.dtype(), DataType::Int64 | DataType::Datetime(_, _)) { /* convert first */ } Type guard
fn datetime_convertible(dt: &DataType) -> bool { matches!(dt, DataType::Int64 | DataType::Datetime(_, _)) } Try / catch
let s: PolarsResult<Series> = series.strict_cast(&DataType::Datetime(TimeUnit::Ns, None));
Prevention
- Ensure epoch values are Int64 in the target time unit
- Widen Int32 epochs before into_datetime
- Use strict_cast for Result-based temporal conversion
When it happens
Trigger: Calling into_datetime(timeunit, tz) on a series whose dtype is neither Int64 nor DataType::Datetime (e.g. Int32, Date, String).
Common situations: Reinterpreting Date or Int32 epoch columns as Datetime directly; unit mismatches where epoch seconds were stored as Int32 and must be widened to Int64 first.
Related errors
- not implemented
- activate dtype
- date not implemented for
- into_decimal( , ) not implemented for
- invalid from_physical
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/9ad0828cfc7f7fea.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-core/src/series/mod.rs:997
panic!("activate feature dtype-datetime")
}
#[cfg(feature = "dtype-datetime")]
match self.dtype() {
DataType::Int64 => self
.i64()
.unwrap()
.clone()
.into_datetime(timeunit, tz)
.into_series(),
DataType::Datetime(_, _) => self
.datetime()
.unwrap()
.physical()
.clone()
.into_datetime(timeunit, tz)
.into_series(),
dt => panic!("into_datetime not implemented for {dt:?}"),
}
}
#[allow(unused_variables)]
pub fn into_duration(self, timeunit: TimeUnit) -> Series {
#[cfg(not(feature = "dtype-duration"))]
{
panic!("activate feature dtype-duration")
}
#[cfg(feature = "dtype-duration")]
match self.dtype() {
DataType::Int64 => self
.i64()
.unwrap()
.clone()
.into_duration(timeunit)
.into_series(),
DataType::Duration(_) => selfView on GitHub (pinned to fe841f959e)