-
Notifications
You must be signed in to change notification settings - Fork 62
feat: add support for np.isnan and np.isfinite ufuncs
#2188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
1388ae7
2f13311
07e677b
99afbda
3b0af20
8f67cb2
aae2902
41ce94b
c0b5e68
7f1bca4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,3 +89,21 @@ def sqrt_op_impl( | |
| import polars as pl | ||
|
|
||
| return pl.when(input < 0).then(float("nan")).otherwise(input.sqrt()) | ||
|
|
||
|
|
||
| @polars_compiler.register_op(numeric_ops.IsNanOp) | ||
| def is_nan_op_impl( | ||
| compiler: polars_compiler.PolarsExpressionCompiler, | ||
| op: numeric_ops.SqrtOp, # type: ignore | ||
|
||
| input: pl.Expr, | ||
| ) -> pl.Expr: | ||
| return input.is_nan() | ||
|
|
||
|
|
||
| @polars_compiler.register_op(numeric_ops.IsFiniteOp) | ||
| def is_finite_op_impl( | ||
| compiler: polars_compiler.PolarsExpressionCompiler, | ||
| op: numeric_ops.SqrtOp, # type: ignore | ||
|
||
| input: pl.Expr, | ||
| ) -> pl.Expr: | ||
| return input.is_finite() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,3 +348,19 @@ def output_type(self, *input_types: dtypes.ExpressionType) -> dtypes.ExpressionT | |
| name="unsafe_pow_op", type_signature=op_typing.BINARY_REAL_NUMERIC | ||
| ) | ||
| unsafe_pow_op = UnsafePowOp() | ||
|
|
||
| IsNanOp = base_ops.create_unary_op( | ||
| name="isnanornull", | ||
|
||
| type_signature=op_typing.FixedOutputType( | ||
| dtypes.is_numeric, dtypes.BOOL_DTYPE, "numeric" | ||
| ), | ||
| ) | ||
| isnan_op = IsNanOp() | ||
|
|
||
| IsFiniteOp = base_ops.create_unary_op( | ||
| name="isfinite", | ||
| type_signature=op_typing.FixedOutputType( | ||
| dtypes.is_numeric, dtypes.BOOL_DTYPE, "numeric" | ||
| ), | ||
| ) | ||
| isfinite_op = IsFiniteOp() | ||
Uh oh!
There was an error while loading. Please reload this page.