Skip to content

Commit 36f6007

Browse files
author
Davies Liu
committed
fix microsecond loss in Python 3
1 parent 3009088 commit 36f6007

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

python/pyspark/sql/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def toInternal(self, dt):
188188

189189
def fromInternal(self, ts):
190190
if ts is not None:
191-
return datetime.datetime.fromtimestamp(ts / 1e6)
191+
# using int to avoid precision loss in float
192+
return datetime.datetime.fromtimestamp(ts // 1000000).replace(microsecond=ts % 1000000)
192193

193194

194195
class DecimalType(FractionalType):

0 commit comments

Comments
 (0)