{"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":604,"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":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/datatypes/classes.py#L586-L622","documentation":"Error \"invalid `time_unit`\n\nExpected one of {'ns','us','ms'}, got {time_unit!r}.\" thrown in pola-rs/polars.","triggerScenarios":"Thrown at py-polars/src/polars/datatypes/classes.py:604 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}