timedelta - How can I accurately display numpy.timedelta64? -
as following code makes apparent, representation of numpy.datetime64 falls victim overflow before objects fail work.
import numpy np import datetime def showmedifference( t1, t2 ): dt = t2-t1 dt64_ms = np.array( [ dt ], dtype = "timedelta64[ms]" )[0] dt64_us = np.array( [ dt ], dtype = "timedelta64[us]" )[0] dt64_ns = np.array( [ dt ], dtype = "timedelta64[ns]" )[0] assert( dt64_ms / dt64_ns == 1.0 ) assert( dt64_us / dt64_ms == 1.0 ) assert( dt64_ms / dt64_us == 1.0 ) print str( dt64_ms ) print str( dt64_us ) print str( dt64_ns ) t1 = datetime.datetime( 2014, 4, 1, 12, 0, 0 ) t2 = datetime.datetime( 2014, 4, 1, 12, 0, 1 ) showmedifference( t1, t2 ) t1 = datetime.datetime( 2014, 4, 1, 12, 0, 0 ) t2 = datetime.datetime( 2014, 4, 1, 12, 1, 0 ) showmedifference( t1, t2 ) t1 = datetime.datetime( 2014, 4, 1, 12, 0, 0 ) t2 = datetime.datetime( 2014, 4, 1, 13, 0, 0 ) showmedifference( t1, t2 ) print "these " + np.__version__
1000 milliseconds 1000000 microseconds 1000000000 nanoseconds 60000 milliseconds 60000000 microseconds -129542144 nanoseconds 3600000 milliseconds -694967296 microseconds 817405952 nanoseconds these 1.7.1
is bug in np.timedelta64? if so, idiom / workarounds have people used when working np.timedelta64?
Comments
Post a Comment