pola-rs/polars · error

only Datetime/Duration inputs supported, got {dtype}

Error message

only Datetime/Duration inputs supported, got {dtype}

What it means

Guard in the numpy interop dtype mapping: only Datetime and Duration dtypes (with any time unit) can be converted to numpy datetime/timedelta dtypes; any other polars dtype reaching this helper triggers the error naming the dtype. Convert to a supported type first.

Source

Thrown at crates/polars-python/src/interop/numpy/utils.rs:127

    use numpy::datetime::{Datetime, Timedelta, units};
    match dtype {
        DataType::Datetime(TimeUnit::Milliseconds, _) => {
            Datetime::<units::Milliseconds>::get_dtype(py)
        },
        DataType::Datetime(TimeUnit::Microseconds, _) => {
            Datetime::<units::Microseconds>::get_dtype(py)
        },
        DataType::Datetime(TimeUnit::Nanoseconds, _) => {
            Datetime::<units::Nanoseconds>::get_dtype(py)
        },
        DataType::Duration(TimeUnit::Milliseconds) => {
            Timedelta::<units::Milliseconds>::get_dtype(py)
        },
        DataType::Duration(TimeUnit::Microseconds) => {
            Timedelta::<units::Microseconds>::get_dtype(py)
        },
        DataType::Duration(TimeUnit::Nanoseconds) => Timedelta::<units::Nanoseconds>::get_dtype(py),
        _ => panic!("only Datetime/Duration inputs supported, got {dtype}"),
    }
}

View on GitHub (pinned to 9b5d73fd00)

Solutions

  1. Pass a numpy array with a datetime64 or timedelta64 dtype; cast other dtypes first (e.g. arr.astype('datetime64[us]')).

Example fix

arr = np.array(['2024-01-01'], dtype='datetime64[us]')
pl.from_numpy(arr)
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Calling a numpy interop conversion with an array whose dtype is not datetime64/timedelta64.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19). Data as JSON: /api/errors/e5a114e783aef1cd. Report an issue: GitHub.