MaxGekk commented on code in PR #39239:
URL: https://github.com/apache/spark/pull/39239#discussion_r1058433158


##########
python/pyspark/sql/types.py:
##########
@@ -276,7 +276,15 @@ def toInternal(self, dt: datetime.datetime) -> int:
     def fromInternal(self, ts: int) -> datetime.datetime:
         if ts is not None:
             # using int to avoid precision loss in float
-            return datetime.datetime.fromtimestamp(ts // 
1000000).replace(microsecond=ts % 1000000)
+            return (
+                datetime.datetime
+                # Set the time zone to UTC because the TIMESTAMP type stores 
timestamps
+                # as the number of microseconds from the epoch of 
1970-01-01T00:00:00.000000Z
+                # in the UTC time zone.
+                .fromtimestamp(ts // 1000000, 
tz=datetime.timezone.utc).replace(

Review Comment:
   > TimestampNTZType is a UTC time.
   
   This is NO time zone timestamp that means local or logical timestamp. For 
example, 2022-12-28 20:23:31 could be in UTC, America/Los_Angeles and 
Europe/Amsterdam. The same local timestamp represents 3 different physical 
timestamps.  So, this type matches precisely to
   ```python
   datetime.datetime(year, month, day, hour, minute, second, microsecond, 
tzinfo=None)
   ```
   
   > My understanding was that TimestampType is a local time per Spark's 
session timezone ...
   
   Yep, this one must be bound to a time zone:
   ```python
   datetime.datetime(year, month, day, hour, minute, second, microsecond, 
tzinfo=ZoneInfo('US/Pacific'))
   ```
   or
   ```python
   datetime.datetime(year, month, day, hour, minute, second, microsecond, 
tzinfo=datetime.timezone.utc)
   ```
   



-- 
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]

Reply via email to