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

ruifengz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 1323ab536cf8 [SPARK-55800][PYTHON] Remove the unused type check for 
datetime.date
1323ab536cf8 is described below

commit 1323ab536cf8105d5d661d0c003fcef360206efc
Author: Tian Gao <[email protected]>
AuthorDate: Tue Mar 3 13:56:44 2026 +0800

    [SPARK-55800][PYTHON] Remove the unused type check for datetime.date
    
    ### What changes were proposed in this pull request?
    
    We check if an object is an instance of `datetime.date` when it could be 
`datetime.datetime` - that's unnecessary and pointless because 
`datetime.datetime` is a subclass of `datetime.date`. It's documented in python 
docs so it's guaranteed.
    
    We can also safely convert a `datetime.datetime` object directly. (We have 
been doing that for a long time).
    
    ### Why are the changes needed?
    
    Remove unnecessary and misleading logic.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    CI.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #54581 from gaogaotiantian/fix-expression-datetime.
    
    Authored-by: Tian Gao <[email protected]>
    Signed-off-by: Ruifeng Zheng <[email protected]>
---
 python/pyspark/sql/connect/expressions.py | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/python/pyspark/sql/connect/expressions.py 
b/python/pyspark/sql/connect/expressions.py
index 4a85fa8403cd..0e8bb3c30924 100644
--- a/python/pyspark/sql/connect/expressions.py
+++ b/python/pyspark/sql/connect/expressions.py
@@ -298,11 +298,8 @@ class LiteralExpression(Expression):
                 assert isinstance(value, (str, np.str_))
                 value = str(value)
             elif isinstance(dataType, DateType):
-                assert isinstance(value, (datetime.date, datetime.datetime))
-                if isinstance(value, datetime.date):
-                    value = DateType().toInternal(value)
-                else:
-                    value = DateType().toInternal(value.date())
+                assert isinstance(value, datetime.date)
+                value = DateType().toInternal(value)
             elif isinstance(dataType, TimeType):
                 assert isinstance(value, datetime.time)
                 value = TimeType().toInternal(value)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to