Skip to content

Commit 03a2cfb

Browse files
authored
Fix get_data_yahoo() Bug in windows when satrt date is earlier than 1970-1-1 8:00
Bug reproduce: ``` python3 from pandas_datareader import data as web web.get_data_yahoo("IBM", start='1968-02-28', end='2020-02-08', interval="d") ``` ERROR `Overflow error: mktime argument out of range`
1 parent 90f155a commit 03a2cfb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas_datareader/yahoo/daily.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import json
44
import re
5-
import time
5+
import time, datetime
66

77
from pandas import DataFrame, isnull, notnull, to_datetime
88

@@ -127,7 +127,11 @@ def url(self):
127127
def _get_params(self, symbol):
128128
# This needed because yahoo returns data shifted by 4 hours ago.
129129
four_hours_in_seconds = 14400
130-
unix_start = int(time.mktime(self.start.timetuple()))
130+
unix_zero = datetime.datetime(1970, 1, 1, 8)
131+
if self.start < unix_zero:
132+
unix_start = int((self.start - unix_zero).total_seconds())
133+
else:
134+
unix_start = int(time.mktime(self.start.timetuple()))
131135
unix_start += four_hours_in_seconds
132136
day_end = self.end.replace(hour=23, minute=59, second=59)
133137
unix_end = int(time.mktime(day_end.timetuple()))

0 commit comments

Comments
 (0)