{"record":{"id":"6b68152f636136ee","repo":"pola-rs/polars","slug":"dtype-must-be-of-type-date-datetime-time","errorCode":null,"errorMessage":"`dtype` must be of type {Date, Datetime, Time}","messagePattern":"`dtype` must be of type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/string.py","lineNumber":330,"sourceCode":"        if dtype == Date:\n            return self.to_date(format, strict=strict, exact=exact, cache=cache)\n        elif dtype == Datetime:\n            time_unit = getattr(dtype, \"time_unit\", None)\n            time_zone = getattr(dtype, \"time_zone\", None)\n            return self.to_datetime(\n                format,\n                time_unit=time_unit,\n                time_zone=time_zone,\n                strict=strict,\n                exact=exact,\n                cache=cache,\n                ambiguous=ambiguous,\n            )\n        elif dtype == Time:\n            return self.to_time(format, strict=strict, cache=cache)\n        else:\n            msg = \"`dtype` must be of type {Date, Datetime, Time}\"\n            raise ValueError(msg)\n\n    @unstable()\n    def to_decimal(self, *, scale: int) -> Expr:\n        \"\"\"\n        Convert a String column into a Decimal column.\n\n        .. engine-support:: in-memory, streaming, distributed\n\n        .. warning::\n            This functionality is considered **unstable**. It may be changed\n            at any point without it being considered a breaking change.\n\n        .. versionchanged:: 1.33.0\n            Parameter `inference_length` was removed and `scale` was made non-optional.\n\n        Parameters\n        ----------\n        scale","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/expr/string.py#L312-L348","documentation":"Expr.str.strptime() dispatches on `dtype`: Date calls to_date, Datetime calls to_datetime, Time calls to_time. Any other dtype (String, Int64, etc.) has no string-parsing path, so Polars raises this ValueError. It means you passed a dtype the method cannot convert to.","triggerScenarios":"Calling Expr.str.strptime(pl.Int64, fmt) or strptime(pl.Utf8, ...) — any dtype outside {Date, Datetime, Time}, often from parameterizing dtype generically.","commonSituations":"Passing the source column dtype by mistake instead of the target dtype; dtype chosen via config/dict lookup; assuming strptime converts to numeric types.","solutions":["Pass pl.Date, pl.Datetime, or pl.Time as dtype.","If you need a different target type, parse to Date/Datetime first, then cast with .cast(...).","Fix the variable feeding dtype so it resolves to one of the three temporal dtypes."],"exampleFix":"// before\ndf.select(pl.col('s').str.strptime(pl.Utf8, '%Y-%m-%d'))\n// after\ndf.select(pl.col('s').str.strptime(pl.Date, '%Y-%m-%d'))","handlingStrategy":"validation","validationCode":"if dtype not in (pl.Date, pl.Datetime, pl.Time):\n    raise ValueError(f'dtype must be Date/Datetime/Time, got {dtype}')","typeGuard":"def is_temporal_dtype(dtype) -> bool:\n    return dtype in (pl.Date, pl.Datetime, pl.Time)","tryCatchPattern":"try:\n    expr = pl.col('s').str.strptime(dtype, fmt)\nexcept ValueError:\n    expr = pl.col('s').str.strptime(pl.Datetime, fmt)","preventionTips":["strptime's dtype is the TARGET type, not the source column type.","Use Literal or an explicit enum of allowed dtypes in wrappers.","For non-temporal targets, parse to a temporal type then .cast()."],"tags":["python","polars","value-error","dtype"],"backgroundTag":"unsupported-dtype","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"}