pola-rs/polars · error · ValueError
invalid `time_unit` Expected one of {'ns','us','ms'}, got {
Error message
invalid `time_unit`
Expected one of {'ns','us','ms'}, got {time_unit!r}. What it means
Error "invalid `time_unit` Expected one of {'ns','us','ms'}, got {time_unit!r}." thrown in pola-rs/polars.
Source
Thrown at py-polars/src/polars/datatypes/classes.py:604
-----
The underlying representation of this type is a 64-bit signed integer.
The integer indicates the number of time units since the Unix epoch
(1970-01-01 00:00:00). The number can be negative to indicate datetimes before the
epoch.
"""
time_unit: TimeUnit
time_zone: str | None
def __init__(
self, time_unit: TimeUnit = "us", time_zone: str | tzinfo | None = None
) -> None:
if time_unit not in ("ms", "us", "ns"):
msg = (
"invalid `time_unit`"
f"\n\nExpected one of {{'ns','us','ms'}}, got {time_unit!r}."
)
raise ValueError(msg)
if isinstance(time_zone, tzinfo):
time_zone = str(time_zone)
self.time_unit = time_unit
self.time_zone = time_zone
def __eq__(self, other: PolarsDataType) -> bool: # type: ignore[override]
# allow comparing object instances to class
if type(other) is DataTypeClass and issubclass(other, Datetime):
return True
elif isinstance(other, Datetime):
return (
self.time_unit == other.time_unit and self.time_zone == other.time_zone
)
else:
return False
View on GitHub (pinned to df599052da)
When it happens
Trigger: Thrown at py-polars/src/polars/datatypes/classes.py:604 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/76979527a3709c81.
Report an issue: GitHub.