Skip to content

Commit 1323ab5

Browse files
gaogaotiantianzhengruifeng
authored andcommitted
[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 apache#54581 from gaogaotiantian/fix-expression-datetime. Authored-by: Tian Gao <gaogaotiantian@hotmail.com> Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
1 parent c2a739f commit 1323ab5

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

python/pyspark/sql/connect/expressions.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,8 @@ def __init__(self, value: Any, dataType: DataType) -> None:
298298
assert isinstance(value, (str, np.str_))
299299
value = str(value)
300300
elif isinstance(dataType, DateType):
301-
assert isinstance(value, (datetime.date, datetime.datetime))
302-
if isinstance(value, datetime.date):
303-
value = DateType().toInternal(value)
304-
else:
305-
value = DateType().toInternal(value.date())
301+
assert isinstance(value, datetime.date)
302+
value = DateType().toInternal(value)
306303
elif isinstance(dataType, TimeType):
307304
assert isinstance(value, datetime.time)
308305
value = TimeType().toInternal(value)

0 commit comments

Comments
 (0)