polars.Expr.is_close
-
Check if this expression is close, i.e. almost equal, to the other expression.
Two values
aandbare considered close if the following condition holds:\[|a-b| \le max \{ \text{rel_tol} \cdot max \{ |a|, |b| \}, \text{abs_tol} \}\]- Parameters:
-
- other
-
A literal or expression value to compare with.
- abs_tol
-
Absolute tolerance. This is the maximum allowed absolute difference between two values. Must be non-negative.
- rel_tol
-
Relative tolerance. This is the maximum allowed difference between two values, relative to the larger absolute value. Must be non-negative.
- nans_equal
-
Whether NaN values should be considered equal.
- Returns:
-
- Expr
-
Expression of data type
Boolean.
Notes
The implementation of this method is symmetric and mirrors the behavior of
math.isclose(). Specifically note that this behavior is different tonumpy.isclose().Examples
>>> df = pl.DataFrame({"a": [1.5, 2.0, 2.5], "b": [1.55, 2.2, 3.0]}) >>> df.with_columns(pl.col("a").is_close("b", abs_tol=0.1).alias("is_close")) shape: (3, 3) ┌─────┬──────┬──────────┐ │ a ┆ b ┆ is_close │ │ --- ┆ --- ┆ --- │ │ f64 ┆ f64 ┆ bool │ ╞═════╪══════╪══════════╡ │ 1.5 ┆ 1.55 ┆ true │ │ 2.0 ┆ 2.2 ┆ false │ │ 2.5 ┆ 3.0 ┆ false │ └─────┴──────┴──────────┘
Expr.is_close(
other: IntoExpr,
*,
abs_tol: float = 0.0,
rel_tol: float = 1e-09,
nans_equal: bool = False,
) → Expr
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.is_close.html