pola-rs/polars · error · ValueError
`time_unit` must be one of {{'ms', 'us', 'ns'}}, got {time_u
Error message
`time_unit` must be one of {{'ms', 'us', 'ns'}}, got {time_unit!r} What it means
ValueError raised by _raise_invalid_time_unit: a temporal conversion received a time_unit outside the supported set 'ms'/'us'/'ns'. It is a shared validation helper used by datetime/timedelta conversion entry points; the message names the rejected time_unit value.
Source
Thrown at py-polars/src/polars/_utils/convert.py:224
_raise_invalid_time_unit(time_unit)
def to_py_decimal(prec: int, value: str) -> Decimal:
"""Convert decimal components to a Python Decimal object."""
return _create_decimal_with_prec(prec)(value)
@lru_cache(None)
def _create_decimal_with_prec(
precision: int,
) -> Callable[[str], Decimal]:
# pre-cache contexts so we don't have to spend time on recreating them every time
return Context(prec=precision).create_decimal
def _raise_invalid_time_unit(time_unit: Any) -> NoReturn:
msg = f"`time_unit` must be one of {{'ms', 'us', 'ns'}}, got {time_unit!r}"
raise ValueError(msg)
View on GitHub (pinned to 9b5d73fd00)
Solutions
- Use time_unit 'ms', 'us', or 'ns'.
Example fix
pl.datetime(..., time_unit='us')
Defensive patterns
Strategy: validation
When it happens
Trigger: Invalid time_unit argument.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19).
Data as JSON: /api/errors/40cb34ff356ba8bb.
Report an issue: GitHub.