pola-rs/polars · error · TypeError
`arctan2` expected a `str` or `Expr` got a
Error message
`arctan2` expected a `str` or `Expr` got a `{qualified_type_name(y)}` What it means
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.
Solutions
- Wrap constants with `pl.lit(...)`
- Pass strings or `pl.col(...)` for columns
- Verify which argument failed from the message (`y` here)
Example fix
// before
pl.arctan2(1.0, pl.col("x"))
// after
pl.arctan2(pl.lit(1.0), pl.col("x")) Defensive patterns
Strategy: type-guard
Validate before calling
def to_expr(v):
if isinstance(v, str): return pl.col(v)
if isinstance(v, (int, float)): return pl.lit(v)
return v Type guard
def is_expr_like(v): return isinstance(v, str) or hasattr(v, "_pyexpr")
Prevention
- Wrap constants with pl.lit() before arctan2
- Validate both y and x arguments
- Use pl.col("name") instead of raw values for columns
When it happens
Trigger: Calling `pl.arctan2(1.0, pl.col("x"))` or passing a Series/number/list as `y` (the first coordinate).
Common situations: Passing bare numeric constants; passing a Series instead of an expression; argument-order confusion between y and x.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- `arctan2` expected a `str` or `Expr` got a
- cannot convert Python type
- Expected Polars expression or object convertible to one, got
- expected Series in 'arg_where' if 'eager=True', got
- `format` must be one of
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/73def16501c9a74b.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/functions/lazy.py:1738
│ --- ┆ --- ┆ --- │
│ 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))
def exclude(
columns: str | PolarsDataType | Collection[str] | Collection[PolarsDataType],
*more_columns: str | PolarsDataType,
) -> Expr:
"""
Represent all columns except for the given columns.
Syntactic sugar for `pl.all().exclude(columns)`.
Parameters
----------
columns
The name or datatype of the column(s) to exclude. Accepts regular expression
input. Regular expressions should start with `^` and end with `$`.View on GitHub (pinned to fe841f959e)