Skip to content

Commit 3766903

Browse files
committed
change default start date to 1900-01-01
1 parent dc0de1d commit 3766903

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pytradelib/utils.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from __future__ import print_function
22

3-
import os
43
import time
54
import pytz
65
import pandas as pd
76

87
from pandas.compat import StringIO, bytes_to_str
8+
from pandas.core.datetools import to_datetime
9+
10+
from datetime import datetime
911

10-
import datetime as dt
1112

1213
def batch(list_, size, sleep=None):
1314
list_ = list(list_)
@@ -17,20 +18,21 @@ def batch(list_, size, sleep=None):
1718
end_idx = (i + 1) * size
1819
if end_idx > len_:
1920
end_idx = len_
20-
yield list_[start_idx:end_idx]
21+
result = list_[start_idx:end_idx]
22+
if result:
23+
yield result
2124
if sleep:
2225
print('Sleeping for %d seconds' % sleep)
2326
time.sleep(sleep)
2427

2528

2629
def _sanitize_dates(start, end):
27-
from pandas.core.datetools import to_datetime
2830
start = to_datetime(start)
2931
end = to_datetime(end)
3032
if start is None:
31-
start = dt.datetime(2010, 1, 1)
33+
start = datetime(1900, 1, 1)
3234
if end is None:
33-
end = dt.datetime.today()
35+
end = datetime.today()
3436
return start, end
3537

3638

@@ -41,10 +43,10 @@ def csv_to_df(text):
4143

4244
# Yahoo! Finance sometimes does this awesome thing where they
4345
# return 2 rows for the most recent business day
44-
if len(df) > 2 and df.index[-1] == df.index[-2]: # pragma: no cover
46+
if len(df) > 2 and df.index[-1] == df.index[-2]: # pragma: no cover
4547
df = df[:-1]
4648

47-
# Get rid of unicode charactedf in index name.
49+
# Get rid of unicode characters in index name.
4850
try:
4951
df.index.name = df.index.name.decode('unicode_escape').encode('ascii', 'ignore')
5052
except AttributeError:

0 commit comments

Comments
 (0)