8000 fix plot_stock_market.py to work on python2.7 and numpy1.6 (#9181) · paulha/scikit-learn@20d00a6 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit 20d00a6

Browse files
amuellerpaulha
authored andcommitted
fix plot_stock_market.py to work on python2.7 and numpy1.6 (scikit-learn#9181)
1 parent 5dfeaa8 commit 20d00a6

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

examples/applications/plot_stock_market.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
# #############################################################################
7878
# Retrieve the data from Internet
7979

80+
8081
def quotes_historical_google(symbol, date1, date2):
8182
"""Get the historical data from Google finance.
8283
@@ -102,15 +103,15 @@ def quotes_historical_google(symbol, date1, date2):
102103
'output': 'csv'
103104
})
104105
url = 'http://www.google.com/finance/historical?' + params
105-
with urlopen(url) as response:
106-
dtype = {
107-
'names': ['date', 'open', 'high', 'low', 'close', 'volume'],
108-
'formats': ['object', 'f4', 'f4', 'f4', 'f4', 'f4']
109-
}
110-
converters = {0: lambda s: datetime.strptime(s.decode(), '%d-%b-%y')}
111-
return np.genfromtxt(response, delimiter=',', skip_header=1,
112-
dtype=dtype, converters=converters,
113-
missing_values='-', filling_values=-1)
106+
response = urlopen(url)
107+
dtype = {
108+
'names': ['date', 'open', 'high', 'low', 'close', 'volume'],
109+
'formats': ['object', 'f4', 'f4', 'f4', 'f4', 'f4']
110+
}
111+
converters = {0: lambda s: datetime.strptime(s.decode(), '%d-%b-%y')}
112+
return np.genfromtxt(response, delimiter=',', skip_header=1,
113+
dtype=dtype, converters=converters,
114+
missing_values='-', filling_values=-1)
114115

115116

116117
# Choose a time period reasonably calm (not too long ago so that we get
@@ -182,8 +183,8 @@ def quotes_historical_google(symbol, date1, date2):
182183
quotes_historical_google(symbol, d1, d2) for symbol in symbols
183184
]
184185

185-
close_prices = np.stack([q['close'] for q in quotes])
186-
open_prices = np.stack([q['open'] for q in quotes])
186+
close_prices = np.vstack([q['close'] for q in quotes])
187+
open_prices = np.vstack([q['open'] for q in quotes])
187188

188189
# The daily variations of the quotes are what carry most information
189190
variation = close_prices - open_prices

0 commit comments

Comments
 (0)
0