pola-rs/polars · error · TypeError
`arctan2` expected a `str` or `Expr` got a `{qualified_type_
Error message
`arctan2` expected a `str` or `Expr` got a `{qualified_type_name(y)}` What it means
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.
Source
Thrown at py-polars/src/polars/functions/lazy.py:1763
│ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ f64 │
╞═══════════╪═══════════╪═══════════╡
│ 0.707107 ┆ 0.707107 ┆ 0.785398 │
│ -0.707107 ┆ 0.707107 ┆ -0.785398 │
│ 0.707107 ┆ -0.707107 ┆ 2.356194 │
│ -0.707107 ┆ -0.707107 ┆ -2.356194 │
└───────────┴───────────┴───────────┘
"""
if isinstance(y, str):
y = F.col(y)
if isinstance(x, str):
x = F.col(x)
if not hasattr(x, "_pyexpr"):
msg = f"`arctan2` expected a `str` or `Expr` got a `{qualified_type_name(x)}`"
raise TypeError(msg)
if not hasattr(y, "_pyexpr"):
msg = f"`arctan2` expected a `str` or `Expr` got a `{qualified_type_name(y)}`"
raise TypeError(msg)
return wrap_expr(plr.arctan2(y._pyexpr, x._pyexpr))
@deprecated("`arctan2d` is deprecated; use `arctan2` followed by `.degrees()` instead.")
def arctan2d(y: str | Expr, x: str | Expr) -> Expr:
"""
Compute two argument arctan in degrees.
.. deprecated:: 1.0.0
Use `arctan2` followed by :meth:`Expr.degrees` instead.
Returns the angle (in degrees) in the plane between the positive x-axis
and the ray from the origin to (x,y).
Parameters
----------
yView on GitHub (pinned to df599052da)
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
Example fix
# before
pl.arctan2(1.0, pl.col('x')) # TypeError on y
# after
pl.arctan2(pl.lit(1.0), pl.col('x')) Defensive patterns
Strategy: validation
Validate before calling
def to_operand(v):
if isinstance(v, str):
return pl.col(v)
if not hasattr(v, '_pyexpr'):
return pl.lit(v)
return v
expr = pl.arctan2(to_operand(y), to_operand(x)) Type guard
def is_expr_or_str(v) -> bool:
return isinstance(v, (str, pl.Expr)) Prevention
- Wrap every scalar constant in pl.lit before passing to arctan2
- Move Series data into a frame and reference columns by name inside select
When it happens
Trigger: 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.
Common situations: Porting math.atan2 / numpy.arctan2 calls with scalar operands; passing precomputed Series; forgetting pl.lit for constants.
Related errors
- `arctan2` expected a `str` or `Expr` got a `{qualified_type_
- Series only supports 'vertical' concat strategy
- escape_regex function is unsupported for `Expr`, you may wan
- escape_regex function supports only `str` type, got `{qualif
- expected at least one Series in 'corr' inputs if 'eager=True
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/73def16501c9a74b.
Report an issue: GitHub.