hdaly0 commented on code in PR #42541:
URL: https://github.com/apache/spark/pull/42541#discussion_r1300122104
##########
python/pyspark/sql/types.py:
##########
@@ -442,7 +442,7 @@ def needConversion(self) -> bool:
def toInternal(self, dt: datetime.timedelta) -> Optional[int]:
if dt is not None:
- return (math.floor(dt.total_seconds()) * 1000000) + dt.microseconds
Review Comment:
Yes indeed! I think it's because floats can't store large integers exactly
(see the "description" section of
[MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER#description)).
Inside `.total_seconds()` large microsecond timedeltas get converted to a
single integer storing the number of microseconds. This is then converted to a
double which, unfortunately, cannot fully represent the integer so it gets
incorrectly represented and rounded due to the floating point precision
limitations.
--
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]