{"record":{"id":"b3979176a8371a06","repo":"pola-rs/polars","slug":"unsupported-temporal-data-type-dtype-r","errorCode":null,"errorMessage":"unsupported temporal data type: {dtype!r}","messagePattern":"unsupported temporal data type: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/interchange/utils.py","lineNumber":148,"sourceCode":"\ndef _temporal_dtype_to_polars_dtype(format_str: str, dtype: Dtype) -> PolarsDataType:\n    if (match := re.fullmatch(r\"ts([mun]):(.*)\", format_str)) is not None:\n        time_unit = match.group(1) + \"s\"\n        time_zone = match.group(2) or None\n        return Datetime(\n            time_unit=time_unit,  # type: ignore[arg-type]\n            time_zone=time_zone,\n        )\n    elif format_str == \"tdD\":\n        return Date\n    elif format_str == \"ttu\":\n        return Time\n    elif (match := re.fullmatch(r\"tD([mun])\", format_str)) is not None:\n        time_unit = match.group(1) + \"s\"\n        return Duration(time_unit=time_unit)  # type: ignore[arg-type]\n\n    msg = f\"unsupported temporal data type: {dtype!r}\"\n    raise NotImplementedError(msg)\n\n\ndef get_buffer_length_in_elements(buffer_size: int, dtype: Dtype) -> int:\n    \"\"\"Get the length of a buffer in elements.\"\"\"\n    bits_per_element = dtype[1]\n    bytes_per_element, rest = divmod(bits_per_element, 8)\n    if rest > 0:\n        msg = f\"cannot get buffer length for buffer with dtype {dtype!r}\"\n        raise ValueError(msg)\n    return buffer_size // bytes_per_element\n\n\ndef polars_dtype_to_data_buffer_dtype(dtype: PolarsDataType) -> PolarsDataType:\n    \"\"\"Get the data type of the data buffer.\"\"\"\n    if dtype.is_integer() or dtype.is_float() or dtype == Boolean:\n        return dtype\n    elif dtype.is_temporal():\n        return Int32 if dtype == Date else Int64","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/interchange/utils.py#L130-L166","documentation":"Temporal interchange dtypes are recognized by their format string: 'ts<m|u|n>:<tz>' -> Datetime, 'tdD' -> Date, 'ttu' -> Time, 'tD<m|u|n>' -> Duration. Any other DATETIME-kind format string — e.g. second-precision timestamps ('tss:...'), or an unrecognized unit — raises NotImplementedError('unsupported temporal data type: ...').","triggerScenarios":"pl.from_dataframe(obj) where a producer declares temporal columns with format strings outside the recognized set, most notably second-unit timestamps ('tss:UTC') or hour/week durations ('tDh').","commonSituations":"Producers whose native clock granularity is seconds (databases, some scientific formats); custom interchange adapters hand-building Dtype tuples and guessing the format-string grammar; newer protocol producers adding units Polars does not map.","solutions":["Change the producer to emit millisecond/microsecond/nanosecond units ('tsm:'/'tsu:'/'tsn:') or 'tdD'/'ttu'.","Convert the columns to a supported representation on the producer (e.g. int64 microseconds, or a pyarrow timestamp with us unit).","Catch NotImplementedError and import the offending column through the Arrow path instead."],"exampleFix":"# producer side, before\n return (DtypeKind.DATETIME, 64, \"tss:UTC\", \"=\")  # seconds -> NotImplementedError\n# after\n return (DtypeKind.DATETIME, 64, \"tsu:UTC\", \"=\")  # microseconds, supported","handlingStrategy":"try-catch","validationCode":"import re\n\nSUPPORTED_TEMPORAL = re.compile(r\"^(ts[mun]:.*|tdD|ttu|tD[mun])$\")\n\nbad = [\n    (i, icdf.get_column(i).dtype)\n    for i in range(icdf.num_columns())\n    if icdf.get_column(i).dtype[0] == DtypeKind.DATETIME\n    and not SUPPORTED_TEMPORAL.fullmatch(icdf.get_column(i).dtype[2])\n]","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.from_dataframe(obj)\nexcept NotImplementedError as e:\n    if \"unsupported temporal data type\" not in str(e):\n        raise\n    # re-express the column on the producer in 'tsu:'/'tdD'/'ttu', then retry","preventionTips":["Emit only m/u/n time units in temporal format strings; avoid second-precision ('tss') and hour durations ('tDh').","Upgrade Polars when producers adopt new temporal format strings.","Convert second-resolution timestamps to microseconds on the producer before export."],"tags":["polars","interchange-protocol","temporal","datetime","time-unit","notimplementederror"],"backgroundTag":"unsupported-temporal-dtype","analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}