Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3 Timedelta OverflowError

I have a large database that I am loading into an in-memory cache. I have a process that does this iterating through the data day by day.

Recently this process has started throwing the following error:

OverflowError: date value out of range for the line

start_day = start_day - datetime.timedelta(days = 1)

This is running in Python 3.4.3 on Ubuntu 14.04.5

like image 564
apardes Avatar asked Mar 06 '23 16:03

apardes


1 Answers

You have reached datetime.date.min, or the first of January of the year 1:

>>> from datetime import date, timedelta
>>> date.min
datetime.date(1, 1, 1)
>>> date.min - timedelta(days=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: date value out of range

If you started at datetime.date.today(), then it took your code a little over 736k steps to get there:

>>> date.today().toordinal()
736766

Your code probably has a bug somewhere that is subtracting too often.

like image 189
Martijn Pieters Avatar answered Mar 09 '23 06:03

Martijn Pieters