I want to find the maximum np.datetime64[ns]
(so that in my algorithm min()
never chooses it). I've tried the suggestion from What is the maximum timestamp numpy.datetime64 can handle? but this gives strange (very wrong!) results in nanosecond resolution:
>>> from datetime import datetime
>>> import numpy as np
>>> np.datetime64(datetime.max, "ns")
numpy.datetime64('1816-03-30T05:56:08.066276376')
I assume this is because datetime.max
is a later date than the maximum np.datetime64[ns]
, so it wraps when converting.
Edit: I've found np.datetime64((1 << 63) - 1, 'ns')
works (I assume that is the maximum), but is obviously gross. Is there a nicer way to construct this?