Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion histogrammar/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def _is_probable_timestamp(value, DATE_LOW=5e16, DATE_HIGH=9.9e18):

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

Expand Down
13 changes: 13 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pickle
import sys
import unittest
import numpy as np

from histogrammar.defs import Factory
from histogrammar.primitives.average import Average
Expand All @@ -40,6 +41,7 @@

from histogrammar import util
from histogrammar.util import xrange, named
from histogrammar.util import _is_probable_timestamp

tolerance = 1e-12
util.relativeTolerance = tolerance
Expand Down Expand Up @@ -170,6 +172,7 @@ def runTest(self):
self.testPlotProfileErr()
self.testPlotStack()
self.testSparselyBin()
self.testIsProbableTimestamp()
self.testCentrallyBin()
self.testFraction()
self.testFractionSum()
Expand Down Expand Up @@ -902,6 +905,16 @@ def testSparselyBinWithFloatBinWidth(self):
self.assertEqual(len(edges), 3)
self.assertEqual(len(entries), 2)
self.assertEqual(list(entries), [0, 0])

def testIsProbableTimestamp(self):
self.assertEqual(True,_is_probable_timestamp(np.int64(9e17)))
self.assertEqual(True,_is_probable_timestamp(np.double(7.9e16)))
self.assertEqual(True,_is_probable_timestamp(7.9e16))
self.assertEqual(True,_is_probable_timestamp(6e16))
self.assertEqual(False,_is_probable_timestamp(np.float32(4.9e16)))
self.assertEqual(False,_is_probable_timestamp(False))
self.assertEqual(False,_is_probable_timestamp("7.9e16"))


# CentrallyBin

Expand Down