{"record":{"id":"644995c06f804a16","repo":"pola-rs/polars","slug":"time-unit-must-be-one-of-valid-units-got-tim","errorCode":null,"errorMessage":"`time_unit` must be one of {valid_units}, got {time_unit!r}","messagePattern":"`time_unit` must be one of (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/lazy.py","lineNumber":2514,"sourceCode":"        column = F.col(column)\n    elif not isinstance(column, (pl.Series, pl.Expr)):\n        column = pl.Series(column)\n\n    if time_unit == \"d\":\n        return column.cast(Date)\n    if time_unit in (scale := {\"s\": 1_000_000, \"ms\": 1_000}):\n        if isinstance(column, pl.Expr):\n            column = column * F.lit(scale[time_unit], dtype=Int64)\n            return column.cast(Datetime(\"us\"))\n        if column.dtype.is_integer():\n            column = column.cast(Int64)\n        return (column * scale[time_unit]).cast(Datetime(\"us\"))\n    if time_unit in DTYPE_TEMPORAL_UNITS:\n        return column.cast(Datetime(time_unit))  # type: ignore[arg-type]\n\n    valid_units = \"'ns', 'us', 'ms', 's', 'd'\"\n    msg = f\"`time_unit` must be one of {valid_units}, got {time_unit!r}\"\n    raise ValueError(msg)\n\n\n@removed_parameters(\n    RenamedParameter(\n        name=\"min_periods\",\n        new_name=\"min_samples\",\n        deprecated_in=\"1.21.0\",\n        removed_in=\"2.0\",\n    ),\n)\ndef rolling_cov(\n    a: str | Expr,\n    b: str | Expr,\n    *,\n    window_size: int,\n    min_samples: int | None = None,\n    ddof: int = 1,\n) -> Expr:","sourceCodeStart":2496,"sourceCodeEnd":2532,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/functions/lazy.py#L2496-L2532","documentation":"`pl.from_epoch(column, time_unit=...)` converts integer epoch timestamps; only 'ns', 'us', 'ms', 's', 'd' are accepted time units. Any other value falls through the unit checks and raises ValueError listing the valid units. Note that for 'ns'/'us'/'ms'/'s' multiplication scaling applies, and 'd' casts to a Date-like unit.","triggerScenarios":"`pl.from_epoch(col, time_unit=\"sec\")`, `time_unit=\"seconds\"`, `time_unit=\"µs\"`, or any misspelled/unsupported unit string.","commonSituations":"Using pandas-style unit strings ('s' vs 'sec'); assuming lowercase/abbreviated variants are accepted; migrating code with nonstandard unit names.","solutions":["Use one of 'ns', 'us', 'ms', 's', 'd' exactly","Map your unit: seconds→'s', microseconds→'us', milliseconds→'ms', nanoseconds→'ns', days→'d'","Check the source of `time_unit` for case or whitespace issues"],"exampleFix":"// before\npl.from_epoch(col, time_unit=\"seconds\")\n// after\npl.from_epoch(col, time_unit=\"s\")","handlingStrategy":"validation","validationCode":"VALID_EPOCH_UNITS = {\"ns\", \"us\", \"ms\", \"s\", \"d\"}\nif time_unit not in VALID_EPOCH_UNITS:\n    raise ValueError(f\"time_unit must be one of {sorted(VALID_EPOCH_UNITS)}\")","typeGuard":"def is_valid_time_unit(u): return isinstance(u, str) and u in {\"ns\", \"us\", \"ms\", \"s\", \"d\"}","tryCatchPattern":null,"preventionTips":["Normalize unit aliases ('sec'→'s', 'msec'→'ms') at ingestion","Keep unit constants in one place","Avoid pandas unit spellings when calling polars APIs"],"tags":["python","polars","datetime","invalid-enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}