HyukjinKwon commented on a change in pull request #33877:
URL: https://github.com/apache/spark/pull/33877#discussion_r703075783
##########
File path: python/pyspark/sql/types.py
##########
@@ -1665,7 +1665,35 @@ def convert(self, obj, gateway_client):
t.setNanos(obj.microsecond * 1000)
return t
+
+class DatetimeNTZConverter(object):
+ def can_convert(self, obj):
+ def prefer_timestamp_ntz():
+ from pyspark.sql import SparkSession
+
+ session = SparkSession._activeSession
+
+ with SparkContext._lock:
+ context = SparkContext._active_spark_context
+ if context is not None and session is not None:
+ return session._is_timestamp_ntz_preferred()
+ else:
+ return False
+
+ return isinstance(obj, datetime.datetime) and obj.tzinfo is None and
prefer_timestamp_ntz()
+
+ def convert(self, obj, gateway_client):
+ from pyspark import SparkContext
+
+ seconds = calendar.timegm(obj.utctimetuple())
+ jvm = SparkContext._jvm
+ return
jvm.org.apache.spark.sql.catalyst.util.DateTimeUtils.microsToLocalDateTime(
+ int(seconds) * 1000000 + obj.microsecond
Review comment:
Python one doesn't have overflow :). This is also consistent with other
places of conversion in Python.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]