14
14
from pandas .io .common import urlencode
15
15
from pandas .compat import StringIO , bytes_to_str
16
16
17
- from pandas_datareader ._utils import RemoteDataError , SymbolWarning
17
+ from pandas_datareader ._utils import (RemoteDataError , SymbolWarning ,
18
+ _sanitize_dates , _init_session )
18
19
19
20
import requests_ftp
20
21
requests_ftp .monkeypatch_session ()
@@ -47,7 +48,7 @@ def __init__(self, symbols, start=None, end=None,
47
48
retry_count = 3 , pause = 0.1 , timeout = 30 , session = None ):
48
49
self .symbols = symbols
49
50
50
- start , end = self . _sanitize_dates (start , end )
51
+ start , end = _sanitize_dates (start , end )
51
52
self .start = start
52
53
self .end = end
53
54
@@ -56,14 +57,7 @@ def __init__(self, symbols, start=None, end=None,
56
57
self .retry_count = retry_count
57
58
self .pause = pause
58
59
self .timeout = timeout
59
- self .session = self ._init_session (session , retry_count )
60
-
61
- def _init_session (self , session , retry_count ):
62
- if session is None :
63
- session = requests .Session ()
64
- session .mount ('file://' , FileAdapter ())
65
- # do not set requests max_retries here to support arbitrary pause
66
- return session
60
+ self .session = _init_session (session , retry_count )
67
61
68
62
@property
69
63
def url (self ):
@@ -143,27 +137,6 @@ def _read_lines(self, out):
143
137
rs .index .name = rs .index .name .encode ('ascii' , 'ignore' ).decode ()
144
138
return rs
145
139
146
- def _sanitize_dates (self , start , end ):
147
- """
148
- Return (datetime_start, datetime_end) tuple
149
- if start is None - default is 2010/01/01
150
- if end is None - default is today
151
- """
152
- if is_number (start ):
153
- # regard int as year
154
- start = dt .datetime (start , 1 , 1 )
155
- start = to_datetime (start )
156
-
157
- if is_number (end ):
158
- end = dt .datetime (end , 1 , 1 )
159
- end = to_datetime (end )
160
-
161
- if start is None :
162
- start = dt .datetime (2010 , 1 , 1 )
163
- if end is None :
164
- end = dt .datetime .today ()
165
- return start , end
166
-
167
140
168
141
class _DailyBaseReader (_BaseReader ):
169
142
""" Base class for Google / Yahoo daily reader """
0 commit comments