{"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":567,"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":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/expr/datetime.py#L549-L585","documentation":"Expr.dt.combine merges a Date column with a time of day. The 'time' argument must be a datetime.time instance or a polars Expr yielding times; strings, tuples, pandas.Timestamp, or np.datetime64 all fail the isinstance check and raise TypeError. Parse such values before calling.","triggerScenarios":"pl.col('date').dt.combine('04:05:06'), .dt.combine((4, 5, 6)), or .dt.combine(pd.Timestamp('04:05:06')).","commonSituations":"Times read from JSON/YAML config as strings; interop code passing pandas Timestamps; tuple hour/minute/second data from legacy schemas.","solutions":["Parse strings first: datetime.time.fromisoformat('04:05:06')","Build an expression literal: pl.time(4, 5, 6)","Convert pandas Timestamps via .to_pydatetime().time()"],"exampleFix":"# before\npl.col('date').dt.combine('04:05:06')  # TypeError\n\n# after\nimport datetime as dt\npl.col('date').dt.combine(dt.time.fromisoformat('04:05:06'))\n# or\npl.col('date').dt.combine(pl.time(4, 5, 6))","handlingStrategy":"type-guard","validationCode":"import datetime as dt\n\nif isinstance(time, str):\n    time = dt.time.fromisoformat(time)\nexpr = pl.col('date').dt.combine(time)","typeGuard":"import datetime as dt\nimport polars as pl\n\ndef is_time_or_expr(t) -> bool:\n    return isinstance(t, (dt.time, pl.Expr))","tryCatchPattern":null,"preventionTips":["Parse ISO time strings with dt.time.fromisoformat at the boundary","Convert pandas Timestamps with .to_pydatetime().time() before combining"],"tags":["datetime","time","type-guard","combine"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}