From 20b474335c68c644150fdc8443a2d0d2dad5e27d Mon Sep 17 00:00:00 2001 From: Davies Liu Date: Sun, 12 Jul 2015 20:25:06 -0700 Subject: [SPARK-9006] [PYSPARK] fix microsecond loss in Python 3 It may loss a microsecond if using timestamp as float, should be `int` instead. Author: Davies Liu Closes #7363 from davies/fix_microsecond and squashes the following commits: 36f6007 [Davies Liu] fix microsecond loss in Python 3 --- python/pyspark/sql/types.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'python/pyspark') diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index d638576916..f75791fad1 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -188,7 +188,8 @@ class TimestampType(AtomicType): def fromInternal(self, ts): if ts is not None: - return datetime.datetime.fromtimestamp(ts / 1e6) + # using int to avoid precision loss in float + return datetime.datetime.fromtimestamp(ts // 1000000).replace(microsecond=ts % 1000000) class DecimalType(FractionalType): -- cgit v1.2.3