Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What determines Pandas minimum and maximum timestamp?

The minimum Timestamp in Pandas is:

pd.Timestamp.min
Timestamp('1677-09-21 00:12:43.145225')

and the maximum is:

pd.Timestamp.max
Timestamp('2262-04-11 23:47:16.854775807')

This means you can't convert a value outside this range to a Pandas datetime:

pd.Timestamp(datetime.date(2500, 1, 1))
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2500-01-01 00:00:00

What determines these limits?

like image 543
willk Avatar asked Nov 20 '25 10:11

willk


1 Answers

The datetime type is stored in nanoseconds using a signed 64 bit integer. The range, then, is [2^-63;2^63 -1 ]. Using the 0 as the unix epoch (1970/01/01 00:00:00.0), you can see by running this code that the result is approximately 292 years from the 0 (unix epoch). The maximum, then, is the date represented with a leading 0 followed by 63 1

Run this code to prove it yourself.

max_int=2**63-1 # maximum integer
max_int/=10**9 # from nanoseconds to seconds
max_int/=86400 # from seconds to days
max_int/=365 # from days to years (suppose no leap years)
print(1970+max_int) # print the maximum year, with an error of days

EDIT: as written in the comment below by Ben, I didn't report the source. here

like image 78
pittix Avatar answered Nov 23 '25 02:11

pittix