Skip to content

Commit 32f5cee

Browse files
committed
Add is_nan aliases
1 parent 699e00e commit 32f5cee

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

python/datafusion/expr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,12 @@ def isnan(self) -> Expr:
12261226

12271227
return F.isnan(self)
12281228

1229+
def is_nan(self) -> Expr:
1230+
"""Returns true if a given number is +NaN or -NaN otherwise returns false."""
1231+
from . import functions as F
1232+
1233+
return F.is_nan(self)
1234+
12291235
def degrees(self) -> Expr:
12301236
"""Converts the argument from radians to degrees."""
12311237
from . import functions as F

python/datafusion/functions/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def _warn_if_expr_for_literal_arg(
217217
"initcap",
218218
"inner_product",
219219
"instr",
220+
"is_nan",
220221
"isnan",
221222
"iszero",
222223
"lag",
@@ -413,6 +414,11 @@ def isnan(expr: Expr) -> Expr:
413414
return Expr(f.isnan(expr.expr))
414415

415416

417+
def is_nan(expr: Expr) -> Expr:
418+
"""Returns true if a given number is +NaN or -NaN otherwise returns false."""
419+
return isnan(expr)
420+
421+
416422
def nullif(expr1: Expr, expr2: Expr) -> Expr:
417423
"""Returns NULL if expr1 equals expr2; otherwise it returns expr1.
418424

python/tests/test_expr.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ def test_alias_with_metadata(df):
500500
pa.array([False, True, False, None], type=pa.bool_()),
501501
id="isnan",
502502
),
503+
pytest.param(
504+
col("e").is_nan(),
505+
pa.array([False, True, False, None], type=pa.bool_()),
506+
id="is_nan",
507+
),
503508
pytest.param(
504509
functions.round(col("a").degrees(), lit(4)),
505510
pa.array([-42.9718, 28.6479, 0.0, None], type=pa.float64()),

python/tests/test_functions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ def test_math_functions():
215215
)
216216

217217

218+
def test_is_nan_alias():
219+
ctx = SessionContext()
220+
df = ctx.from_pydict({"value": [1.0, np.nan, None]})
221+
222+
result = df.select(f.is_nan(column("value")).alias("is_nan")).to_pydict()
223+
224+
assert result == {"is_nan": [False, True, None]}
225+
226+
218227
def py_indexof(arr, v):
219228
try:
220229
return arr.index(v) + 1

0 commit comments

Comments
 (0)