{"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":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/lazy.py","lineNumber":1763,"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\n@deprecated(\"`arctan2d` is deprecated; use `arctan2` followed by `.degrees()` instead.\")\ndef arctan2d(y: str | Expr, x: str | Expr) -> Expr:\n    \"\"\"\n    Compute two argument arctan in degrees.\n\n    .. deprecated:: 1.0.0\n        Use `arctan2` followed by :meth:`Expr.degrees` instead.\n\n    Returns the angle (in degrees) in the plane between the positive x-axis\n    and the ray from the origin to (x,y).\n\n    Parameters\n    ----------\n    y","sourceCodeStart":1745,"sourceCodeEnd":1781,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/functions/lazy.py#L1745-L1781","documentation":"Same validation as the x argument: pl.arctan2(y, x) requires y to be a str column name or an Expr. The y check runs after x, so a bad y raises only once x is acceptable. Numeric literals, Series, and None in the y position produce this TypeError.","triggerScenarios":"pl.arctan2(1.0, pl.col('x')); pl.arctan2(s_y_series, 'x'); pl.arctan2(None, 'x'). Argument-order mistakes often put the literal in y expecting numpy's (y, x) convention — which is in fact correct here, but both slots must be expressions.","commonSituations":"Porting math.atan2 / numpy.arctan2 calls with scalar operands; passing precomputed Series; forgetting pl.lit for constants.","solutions":["Wrap constants: pl.arctan2(pl.lit(1.0), pl.col('x'))","Use column names (str) for frame columns, or build Exprs explicitly","Move Series data into a DataFrame and select with named columns"],"exampleFix":"# before\npl.arctan2(1.0, pl.col('x'))  # TypeError on y\n\n# after\npl.arctan2(pl.lit(1.0), pl.col('x'))","handlingStrategy":"validation","validationCode":"def to_operand(v):\n    if isinstance(v, str):\n        return pl.col(v)\n    if not hasattr(v, '_pyexpr'):\n        return pl.lit(v)\n    return v\n\nexpr = pl.arctan2(to_operand(y), to_operand(x))","typeGuard":"def is_expr_or_str(v) -> bool:\n    return isinstance(v, (str, pl.Expr))","tryCatchPattern":null,"preventionTips":["Wrap every scalar constant in pl.lit before passing to arctan2","Move Series data into a frame and reference columns by name inside select"],"tags":["polars","arctan2","expr","input-validation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}