{"record":{"id":"73def16501c9a74b","repo":"pola-rs/polars","slug":"arctan2-expected-a-str-or-expr-got-a-quali-73def1","errorCode":null,"errorMessage":"`arctan2` expected a `str` or `Expr` got a `{qualified_type_name(y)}`","messagePattern":"`arctan2` expected a `str` or `Expr` got a `(.+?)`","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/lazy.py","lineNumber":1738,"sourceCode":"    │ ---       ┆ ---       ┆ ---       │\n    │ f64       ┆ f64       ┆ f64       │\n    ╞═══════════╪═══════════╪═══════════╡\n    │ 0.707107  ┆ 0.707107  ┆ 0.785398  │\n    │ -0.707107 ┆ 0.707107  ┆ -0.785398 │\n    │ 0.707107  ┆ -0.707107 ┆ 2.356194  │\n    │ -0.707107 ┆ -0.707107 ┆ -2.356194 │\n    └───────────┴───────────┴───────────┘\n    \"\"\"\n    if isinstance(y, str):\n        y = F.col(y)\n    if isinstance(x, str):\n        x = F.col(x)\n    if not hasattr(x, \"_pyexpr\"):\n        msg = f\"`arctan2` expected a `str` or `Expr` got a `{qualified_type_name(x)}`\"\n        raise TypeError(msg)\n    if not hasattr(y, \"_pyexpr\"):\n        msg = f\"`arctan2` expected a `str` or `Expr` got a `{qualified_type_name(y)}`\"\n        raise TypeError(msg)\n\n    return wrap_expr(plr.arctan2(y._pyexpr, x._pyexpr))\n\n\ndef exclude(\n    columns: str | PolarsDataType | Collection[str] | Collection[PolarsDataType],\n    *more_columns: str | PolarsDataType,\n) -> Expr:\n    \"\"\"\n    Represent all columns except for the given columns.\n\n    Syntactic sugar for `pl.all().exclude(columns)`.\n\n    Parameters\n    ----------\n    columns\n        The name or datatype of the column(s) to exclude. Accepts regular expression\n        input. Regular expressions should start with `^` and end with `$`.","sourceCodeStart":1720,"sourceCodeEnd":1756,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/functions/lazy.py#L1720-L1756","documentation":"Type guard in pl.arctan2: both x and y must be column-name strings or Exprs so they can be converted to expressions. When x lacks the _pyexpr attribute (e.g. a raw number, Series, or ndarray), the required expression conversion is impossible and TypeError is raised.","triggerScenarios":"Calling `pl.arctan2(1.0, pl.col(\"x\"))` or passing a Series/number/list as `y` (the first coordinate).","commonSituations":"Passing bare numeric constants; passing a Series instead of an expression; argument-order confusion between y and x.","solutions":["Wrap constants with `pl.lit(...)`","Pass strings or `pl.col(...)` for columns","Verify which argument failed from the message (`y` here)"],"exampleFix":"// before\npl.arctan2(1.0, pl.col(\"x\"))\n// after\npl.arctan2(pl.lit(1.0), pl.col(\"x\"))","handlingStrategy":"type-guard","validationCode":"def to_expr(v):\n    if isinstance(v, str): return pl.col(v)\n    if isinstance(v, (int, float)): return pl.lit(v)\n    return v","typeGuard":"def is_expr_like(v): return isinstance(v, str) or hasattr(v, \"_pyexpr\")","tryCatchPattern":null,"preventionTips":["Wrap constants with pl.lit() before arctan2","Validate both y and x arguments","Use pl.col(\"name\") instead of raw values for columns"],"tags":["python","polars","expression","type-mismatch"],"backgroundTag":"invalid-argument-value","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"}