{"record":{"id":"64090d79f411dd2c","repo":"pola-rs/polars","slug":"expected-time-to-be-a-python-time-or-polars-expr","errorCode":null,"errorMessage":"expected 'time' to be a Python time or Polars expression, found {qualified_type_name(time)!r}","messagePattern":"expected 'time' to be a Python time or Polars expression, found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/datetime.py","lineNumber":563,"sourceCode":"        ...     [\n        ...         pl.col(\"dtm\").dt.combine(pl.col(\"tm\")).alias(\"d1\"),\n        ...         pl.col(\"dt\").dt.combine(pl.col(\"tm\")).alias(\"d2\"),\n        ...         pl.col(\"dt\").dt.combine(time(4, 5, 6)).alias(\"d3\"),\n        ...     ]\n        ... )\n        shape: (2, 3)\n        ┌─────────────────────────┬─────────────────────────┬─────────────────────┐\n        │ d1                      ┆ d2                      ┆ d3                  │\n        │ ---                     ┆ ---                     ┆ ---                 │\n        │ datetime[μs]            ┆ datetime[μs]            ┆ datetime[μs]        │\n        ╞═════════════════════════╪═════════════════════════╪═════════════════════╡\n        │ 2022-12-31 01:02:03.456 ┆ 2022-10-10 01:02:03.456 ┆ 2022-10-10 04:05:06 │\n        │ 2023-07-05 07:08:09.101 ┆ 2022-07-05 07:08:09.101 ┆ 2022-07-05 04:05:06 │\n        └─────────────────────────┴─────────────────────────┴─────────────────────┘\n        \"\"\"\n        if not isinstance(time, (dt.time, pl.Expr)):\n            msg = f\"expected 'time' to be a Python time or Polars expression, found {qualified_type_name(time)!r}\"\n            raise TypeError(msg)\n        time_pyexpr = parse_into_expression(time)\n        return wrap_expr(self._pyexpr.dt_combine(time_pyexpr, time_unit))\n\n    def to_string(self, format: str | None = None) -> Expr:\n        \"\"\"\n        Convert a Date/Time/Datetime column into a String column with the given format.\n\n        .. engine-support:: in-memory, streaming, distributed\n\n        .. versionchanged:: 1.15.0\n            Added support for the use of \"iso:strict\" as a format string.\n        .. versionchanged:: 1.14.0\n            Added support for the `Duration` dtype, and use of \"iso\" as a format string.\n\n        Parameters\n        ----------\n        format\n            * Format to use, refer to the `chrono strftime documentation","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/expr/datetime.py#L545-L581","documentation":"Expr.dt.combine joins a date column with a time to produce a datetime; the time argument must be a datetime.time instance or a polars Expr. Anything else raises TypeError naming the qualified type found.","triggerScenarios":"Calling pl.col('date').dt.combine('12:30'), combine(datetime.datetime(...)), or passing a string/None instead of dt.time or a pl.Expr.","commonSituations":"Passing time as a string from config ('09:00:00'); using datetime.datetime instead of datetime.time; passing an integer hour; confusion with pandas' combine which takes DatetimeIndex-like args.","solutions":["Wrap the value: time=dt.time(12, 30) or pl.lit('12:30').str.to_time() then pass the Expr","Parse string times first with str.to_time() and pass that expression","Extract the time part if you have a datetime: combine(dt_obj.time())","Add an isinstance(time, (dt.time, pl.Expr)) assertion before the call"],"exampleFix":"// before\npl.col('date').dt.combine('12:30')\n// after\npl.col('date').dt.combine(dt.time(12, 30))","handlingStrategy":"type-guard","validationCode":"import datetime as dt, polars as pl\nif not isinstance(time, (dt.time, pl.Expr)):\n    raise TypeError('time must be datetime.time or pl.Expr')","typeGuard":"import datetime as dt\nimport polars as pl\ndef is_time_or_expr(x) -> bool:\n    return isinstance(x, (dt.time, pl.Expr))","tryCatchPattern":"try:\n    e = col.dt.combine(t)\nexcept TypeError as e:\n    if 'expected .time. to be' in str(e):\n        t = pl.lit(str(t)).str.to_time() if isinstance(t, str) else dt.time(t.hour, t.minute)\n        e = col.dt.combine(t)\n    else:\n        raise","preventionTips":["Use datetime.time objects, not datetime.datetime or strings","Parse string times with str.to_time() and pass the resulting Expr","Keep a helper that converts str|time|datetime into a valid time expression"],"tags":["python","polars","type-error","datetime"],"backgroundTag":"type-mismatch","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"}