1
1
from __future__ import print_function
2
2
3
- import os
4
3
import time
5
4
import pytz
6
5
import pandas as pd
7
6
8
7
from pandas .compat import StringIO , bytes_to_str
8
+ from pandas .core .datetools import to_datetime
9
+
10
+ from datetime import datetime
9
11
10
- import datetime as dt
11
12
12
13
def batch (list_ , size , sleep = None ):
13
14
list_ = list (list_ )
@@ -17,20 +18,21 @@ def batch(list_, size, sleep=None):
17
18
end_idx = (i + 1 ) * size
18
19
if end_idx > len_ :
19
20
end_idx = len_
20
- yield list_ [start_idx :end_idx ]
21
+ result = list_ [start_idx :end_idx ]
22
+ if result :
23
+ yield result
21
24
if sleep :
22
25
print ('Sleeping for %d seconds' % sleep )
23
26
time .sleep (sleep )
24
27
25
28
26
29
def _sanitize_dates (start , end ):
27
- from pandas .core .datetools import to_datetime
28
30
start = to_datetime (start )
29
31
end = to_datetime (end )
30
32
if start is None :
31
- start = dt . datetime (2010 , 1 , 1 )
33
+ start = datetime (1900 , 1 , 1 )
32
34
if end is None :
33
- end = dt . datetime .today ()
35
+ end = datetime .today ()
34
36
return start , end
35
37
36
38
@@ -41,10 +43,10 @@ def csv_to_df(text):
41
43
42
44
# Yahoo! Finance sometimes does this awesome thing where they
43
45
# 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
45
47
df = df [:- 1 ]
46
48
47
- # Get rid of unicode charactedf in index name.
49
+ # Get rid of unicode characters in index name.
48
50
try :
49
51
df .index .name = df .index .name .decode ('unicode_escape' ).encode ('ascii' , 'ignore' )
50
52
except AttributeError :
0 commit comments