Skip to content

Commit 2ef059d

Browse files
pradyot-09Patil
andauthored
fix: spark df timestamp datatype detection (#59)
Co-authored-by: Patil <pradyot.patil@ing.com>
1 parent 0c91545 commit 2ef059d

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

histogrammar/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def _is_probable_timestamp(value, DATE_LOW=5e16, DATE_HIGH=9.9e18):
661661

662662
# timestamp is in ns since 1970, so a huge number.
663663
is_ts = False
664-
if isinstance(value, np.number) and not np.isnan(value):
664+
if isinstance(value, (np.number,float,int)) and not np.isnan(value):
665665
is_ts = DATE_LOW < value < DATE_HIGH
666666
return is_ts
667667

tests/test_basic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import pickle
1919
import sys
2020
import unittest
21+
import numpy as np
2122

2223
from histogrammar.defs import Factory
2324
from histogrammar.primitives.average import Average
@@ -40,6 +41,7 @@
4041

4142
from histogrammar import util
4243
from histogrammar.util import xrange, named
44+
from histogrammar.util import _is_probable_timestamp
4345

4446
tolerance = 1e-12
4547
util.relativeTolerance = tolerance
@@ -170,6 +172,7 @@ def runTest(self):
170172
self.testPlotProfileErr()
171173
self.testPlotStack()
172174
self.testSparselyBin()
175+
self.testIsProbableTimestamp()
173176
self.testCentrallyBin()
174177
self.testFraction()
175178
self.testFractionSum()
@@ -902,6 +905,16 @@ def testSparselyBinWithFloatBinWidth(self):
902905
self.assertEqual(len(edges), 3)
903906
self.assertEqual(len(entries), 2)
904907
self.assertEqual(list(entries), [0, 0])
908+
909+
def testIsProbableTimestamp(self):
910+
self.assertEqual(True,_is_probable_timestamp(np.int64(9e17)))
911+
self.assertEqual(True,_is_probable_timestamp(np.double(7.9e16)))
912+
self.assertEqual(True,_is_probable_timestamp(7.9e16))
913+
self.assertEqual(True,_is_probable_timestamp(6e16))
914+
self.assertEqual(False,_is_probable_timestamp(np.float32(4.9e16)))
915+
self.assertEqual(False,_is_probable_timestamp(False))
916+
self.assertEqual(False,_is_probable_timestamp("7.9e16"))
917+
905918

906919
# CentrallyBin
907920

0 commit comments

Comments
 (0)