You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by ko...@apache.org on 2026/08/03 08:41:37 UTC

(datafusion-python) branch main updated: Add is_nan aliases (#1643)

This is an automated email from the ASF dual-hosted git repository.

kosiew pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 4702915c Add is_nan aliases (#1643)
4702915c is described below

commit 4702915c4f019a251809d5d7d9d2014e7d7c4251
Author: BharatDeva <bh...@gmail.com>
AuthorDate: Mon Aug 3 03:41:32 2026 -0500

    Add is_nan aliases (#1643)
    
    Adds datafusion.functions.is_nan(...) as an alias for isnan(...) and adds Expr.is_nan() as the corresponding expression method. Existing isnan() behavior is unchanged.
    
    The PR also adds coverage for both the function-level alias and the expression method.
---
 python/datafusion/expr.py               | 6 ++++++
 python/datafusion/functions/__init__.py | 6 ++++++
 python/tests/test_expr.py               | 5 +++++
 python/tests/test_functions.py          | 9 +++++++++
 4 files changed, 26 insertions(+)

diff --git a/python/datafusion/expr.py b/python/datafusion/expr.py
index d2560fbc..a086cd32 100644
--- a/python/datafusion/expr.py
+++ b/python/datafusion/expr.py
@@ -1226,6 +1226,12 @@ class Expr:  # noqa: PLW1641
 
         return F.isnan(self)
 
+    def is_nan(self) -> Expr:
+        """Returns true if a given number is +NaN or -NaN otherwise returns false."""
+        from . import functions as F
+
+        return F.is_nan(self)
+
     def degrees(self) -> Expr:
         """Converts the argument from radians to degrees."""
         from . import functions as F
diff --git a/python/datafusion/functions/__init__.py b/python/datafusion/functions/__init__.py
index 9fb20dc1..29195749 100644
--- a/python/datafusion/functions/__init__.py
+++ b/python/datafusion/functions/__init__.py
@@ -217,6 +217,7 @@ __all__ = [
     "initcap",
     "inner_product",
     "instr",
+    "is_nan",
     "isnan",
     "iszero",
     "lag",
@@ -413,6 +414,11 @@ def isnan(expr: Expr) -> Expr:
     return Expr(f.isnan(expr.expr))
 
 
+def is_nan(expr: Expr) -> Expr:
+    """Alias for :func:`isnan`."""
+    return isnan(expr)
+
+
 def nullif(expr1: Expr, expr2: Expr) -> Expr:
     """Returns NULL if expr1 equals expr2; otherwise it returns expr1.
 
diff --git a/python/tests/test_expr.py b/python/tests/test_expr.py
index 606c6a98..9246dd69 100644
--- a/python/tests/test_expr.py
+++ b/python/tests/test_expr.py
@@ -500,6 +500,11 @@ def test_alias_with_metadata(df):
             pa.array([False, True, False, None], type=pa.bool_()),
             id="isnan",
         ),
+        pytest.param(
+            col("e").is_nan(),
+            pa.array([False, True, False, None], type=pa.bool_()),
+            id="is_nan",
+        ),
         pytest.param(
             functions.round(col("a").degrees(), lit(4)),
             pa.array([-42.9718, 28.6479, 0.0, None], type=pa.float64()),
diff --git a/python/tests/test_functions.py b/python/tests/test_functions.py
index 894d81fc..08bec60e 100644
--- a/python/tests/test_functions.py
+++ b/python/tests/test_functions.py
@@ -215,6 +215,15 @@ def test_math_functions():
     )
 
 
+def test_is_nan_alias():
+    ctx = SessionContext()
+    df = ctx.from_pydict({"value": [1.0, np.nan, None]})
+
+    result = df.select(f.is_nan(column("value")).alias("is_nan")).to_pydict()
+
+    assert result == {"is_nan": [False, True, None]}
+
+
 def py_indexof(arr, v):
     try:
         return arr.index(v) + 1


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org