GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add is_nan aliases (#1643) · apache/datafusion-python@4702915

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • python
    • datafusion
      • expr.py
      • functions
        • __init__.py
    • tests
      • test_expr.py
      • test_functions.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎python/datafusion/expr.py‎

Copy file name to clipboardExpand all lines: python/datafusion/expr.py
+6Lines 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
Collapse file

‎python/datafusion/functions/__init__.py‎

Copy file name to clipboardExpand all lines: python/datafusion/functions/__init__.py
+6Lines 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+
"""Alias for :func:`isnan`."""
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
Collapse file

‎python/tests/test_expr.py‎

Copy file name to clipboardExpand all lines: python/tests/test_expr.py
+5Lines 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()),
Collapse file

‎python/tests/test_functions.py‎

Copy file name to clipboardExpand all lines: python/tests/test_functions.py
+9Lines 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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.