You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "zeel2104 (via GitHub)" <gi...@apache.org> on 2026/04/12 12:20:30 UTC

[PR] Support None comparisons for null expressions [datafusion-python]

zeel2104 opened a new pull request, #1489:
URL: https://github.com/apache/datafusion-python/pull/1489

   # Which issue does this PR close?
   
   Closes #1483.
   
   # Rationale for this change
   
   Comparing expressions to `None` with `==` currently builds a regular equality comparison against a null literal, which follows SQL null semantics and does not match null values in filters. This is surprising for Python users, especially since comparing against other scalar values works as expected and the equivalent `.is_null()` expression does return the expected rows.
   
   # What changes are included in this PR?
   
   - Special-case `Expr.__eq__` so `expr == None` maps to `expr.is_null()`
   - Special-case `Expr.__ne__` so `expr != None` maps to `expr.is_not_null()`
   - Add regression tests covering `== None` and `!= None` on nullable integer and string columns
   
   # Are there any user-facing changes?
   
   Yes. Python users can now write `col("a") == None` and `col("a") != None` as shorthand for `is_null()` and `is_not_null()`.
   
   `is None` is not supported because Python identity checks cannot be overloaded.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Support None comparisons for null expressions [datafusion-python]

Posted by "timsaucer (via GitHub)" <gi...@apache.org>.
timsaucer merged PR #1489:
URL: https://github.com/apache/datafusion-python/pull/1489


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Support None comparisons for null expressions [datafusion-python]

Posted by "timsaucer (via GitHub)" <gi...@apache.org>.
timsaucer commented on code in PR #1489:
URL: https://github.com/apache/datafusion-python/pull/1489#discussion_r3069521847


##########
python/tests/test_expr.py:
##########
@@ -173,6 +173,24 @@ def test_relational_expr(test_ctx):
     assert df.filter(col("a") == "beta").count() == 0
 
 
+def test_relational_expr_none_uses_null_predicates():
+    ctx = SessionContext()
+
+    batch = pa.RecordBatch.from_arrays(
+        [
+            pa.array([1, 2, None]),
+            pa.array(["alpha", None, "gamma"], type=pa.string_view()),
+        ],
+        names=["a", "b"],
+    )
+    df = ctx.create_dataframe([[batch]], name="batch_with_nulls")
+
+    assert df.filter(col("a") == None).count() == 1  # noqa: E711
+    assert df.filter(col("a") != None).count() == 2  # noqa: E711
+    assert df.filter(col("b") == None).count() == 1  # noqa: E711
+    assert df.filter(col("b") != None).count() == 2  # noqa: E711

Review Comment:
   I think you can just update the `test_relational_expr` to have some null values and incorporate this into the existing test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] Support None comparisons for null expressions [datafusion-python]

Posted by "zeel2104 (via GitHub)" <gi...@apache.org>.
zeel2104 commented on code in PR #1489:
URL: https://github.com/apache/datafusion-python/pull/1489#discussion_r3070331597


##########
python/tests/test_expr.py:
##########
@@ -173,6 +173,24 @@ def test_relational_expr(test_ctx):
     assert df.filter(col("a") == "beta").count() == 0
 
 
+def test_relational_expr_none_uses_null_predicates():
+    ctx = SessionContext()
+
+    batch = pa.RecordBatch.from_arrays(
+        [
+            pa.array([1, 2, None]),
+            pa.array(["alpha", None, "gamma"], type=pa.string_view()),
+        ],
+        names=["a", "b"],
+    )
+    df = ctx.create_dataframe([[batch]], name="batch_with_nulls")
+
+    assert df.filter(col("a") == None).count() == 1  # noqa: E711
+    assert df.filter(col("a") != None).count() == 2  # noqa: E711
+    assert df.filter(col("b") == None).count() == 1  # noqa: E711
+    assert df.filter(col("b") != None).count() == 2  # noqa: E711

Review Comment:
   Updated the tests to fold the None comparison coverage into `test_relational_expr` and pushed the change. Thanks for the suggestion.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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