{"record":{"id":"76979527a3709c81","repo":"pola-rs/polars","slug":"invalid-time-unit-expected-one-of-ns-us-m","errorCode":null,"errorMessage":"invalid `time_unit`\n\nExpected one of {'ns','us','ms'}, got {time_unit!r}.","messagePattern":"invalid `time_unit`\n\nExpected one of (.+?), got (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/datatypes/classes.py","lineNumber":608,"sourceCode":"    -----\n    The underlying representation of this type is a 64-bit signed integer.\n    The integer indicates the number of time units since the Unix epoch\n    (1970-01-01 00:00:00). The number can be negative to indicate datetimes before the\n    epoch.\n    \"\"\"\n\n    time_unit: TimeUnit\n    time_zone: str | None\n\n    def __init__(\n        self, time_unit: TimeUnit = \"us\", time_zone: str | tzinfo | None = None\n    ) -> None:\n        if time_unit not in (\"ms\", \"us\", \"ns\"):\n            msg = (\n                \"invalid `time_unit`\"\n                f\"\\n\\nExpected one of {{'ns','us','ms'}}, got {time_unit!r}.\"\n            )\n            raise ValueError(msg)\n\n        if isinstance(time_zone, tzinfo):\n            time_zone = str(time_zone)\n\n        self.time_unit = time_unit\n        self.time_zone = time_zone\n\n    def __eq__(self, other: PolarsDataType) -> bool:  # type: ignore[override]\n        # allow comparing object instances to class\n        if type(other) is DataTypeClass and issubclass(other, Datetime):\n            return True\n        elif isinstance(other, Datetime):\n            return (\n                self.time_unit == other.time_unit and self.time_zone == other.time_zone\n            )\n        else:\n            return False\n","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/datatypes/classes.py#L590-L626","documentation":"ValueError raised by Datetime.__init__: the time_unit argument is not one of 'ms', 'us', 'ns', which are the only resolutions a Datetime dtype can carry. The guard fires during dtype construction, echoing the invalid time_unit.","triggerScenarios":"Invalid time_unit for a Datetime/Duration dtype.","commonSituations":"See trigger scenarios.","solutions":["Use time_unit 'ns', 'us', or 'ms'."],"exampleFix":"pl.Datetime(time_unit='us')","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}