Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1def459

Browse files
committed
fixed a collection of stupid bugs (like not returning from
wrapper functions).
1 parent a92039b commit 1def459

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

lib/matplotlib/finance.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def parse_yahoo_historical_ochl(fh, adjusted=True, asobject=False):
116116
very similar to the Bunch.
117117
118118
"""
119-
_parse_yahoo_historical(fh, adjusted=adjusted, asobject=asobject,
120-
oclh=True)
119+
return _parse_yahoo_historical(fh, adjusted=adjusted, asobject=asobject,
120+
ochl=True)
121121

122122

123123
def parse_yahoo_historical_ohlc(fh, adjusted=True, asobject=False):
@@ -160,7 +160,7 @@ def parse_yahoo_historical_ohlc(fh, adjusted=True, asobject=False):
160160
holding 1-D ndarrays. The behavior of a numpy recarray is
161161
very similar to the Bunch.
162162
"""
163-
_parse_yahoo_historical(fh, adjusted=adjusted, asobject=asobject,
163+
return _parse_yahoo_historical(fh, adjusted=adjusted, asobject=asobject,
164164
ochl=False)
165165

166166

@@ -217,11 +217,12 @@ def parse_yahoo_historical(fh, adjusted=True, asobject=False):
217217
Defaults to True to preserve original functionality.
218218
219219
"""
220+
220221
warnings.warn(_warn_str.format(fun='parse_yahoo_historical'),
221222
mplDeprecation)
222223

223-
_parse_yahoo_historical(fh, adjusted=adjusted, asobject=asobject,
224-
oclh=True)
224+
return _parse_yahoo_historical(fh, adjusted=adjusted, asobject=asobject,
225+
ochl=True)
225226

226227

227228
def _parse_yahoo_historical(fh, adjusted=True, asobject=False,
@@ -283,13 +284,11 @@ def _parse_yahoo_historical(fh, adjusted=True, asobject=False,
283284
else:
284285
stock_dt = stock_dt_ohlc
285286

286-
lines = fh.readlines()
287-
288287
results = []
289288

290289
# datefmt = '%Y-%m-%d'
291-
292-
for line in lines[1:]:
290+
fh.readline() # discard heading
291+
for line in fh:
293292

294293
vals = line.split(',')
295294
if len(vals) != 7:
@@ -303,9 +302,13 @@ def _parse_yahoo_historical(fh, adjusted=True, asobject=False,
303302
open, high, low, close = [float(val) for val in vals[1:5]]
304303
volume = float(vals[5])
305304
aclose = float(vals[6])
305+
if ochl:
306+
results.append((dt, dt.year, dt.month, dt.day,
307+
dnum, open, close, high, low, volume, aclose))
306308

307-
results.append((dt, dt.year, dt.month, dt.day,
308-
dnum, open, high, low, close, volume, aclose))
309+
else:
310+
results.append((dt, dt.year, dt.month, dt.day,
311+
dnum, open, high, low, close, volume, aclose))
309312
results.reverse()
310313
d = np.array(results, dtype=stock_dt)
311314
if adjusted:
@@ -459,7 +462,7 @@ def quotes_historical_yahoo(ticker, date1, date2, asobject=False,
459462
warnings.warn(_warn_str.format(fun='quotes_historical_yahoo'),
460463
mplDeprecation)
461464

462-
_quotes_historical_yahoo(ticker, date1, date2, asobject=asobject,
465+
return _quotes_historical_yahoo(ticker, date1, date2, asobject=asobject,
463466
adjusted=adjusted, cachename=cachename,
464467
ochl=True)
465468

@@ -499,7 +502,7 @@ def quotes_historical_yahoo_ochl(ticker, date1, date2, asobject=False,
499502
and date range)
500503
"""
501504

502-
_quotes_historical_yahoo(ticker, date1, date2, asobject=asobject,
505+
return _quotes_historical_yahoo(ticker, date1, date2, asobject=asobject,
503506
adjusted=adjusted, cachename=cachename,
504507
ochl=True)
505508

@@ -539,7 +542,7 @@ def quotes_historical_yahoo_ohlc(ticker, date1, date2, asobject=False,
539542
and date range)
540543
"""
541544

542-
_quotes_historical_yahoo(ticker, date1, date2, asobject=asobject,
545+
return _quotes_historical_yahoo(ticker, date1, date2, asobject=asobject,
543546
adjusted=adjusted, cachename=cachename,
544547
ochl=True)
545548

@@ -639,7 +642,7 @@ def plot_day_summary(ax, quotes, ticksize=3,
639642
warnings.warn(_warn_str.format(fun='plot_day_summary'),
640643
mplDeprecation)
641644

642-
_plot_day_summary(ax, quotes, ticksize=ticksize,
645+
return _plot_day_summary(ax, quotes, ticksize=ticksize,
643646
colorup=colorup, colordown=colordown,
644647
ochl=True)
645648

@@ -673,7 +676,7 @@ def plot_day_summary_oclh(ax, quotes, ticksize=3,
673676
lines : list
674677
list of tuples of the lines added (one tuple per quote)
675678
"""
676-
_plot_day_summary(ax, quotes, ticksize=ticksize,
679+
return _plot_day_summary(ax, quotes, ticksize=ticksize,
677680
colorup=colorup, colordown=colordown,
678681
ochl=True)
679682

@@ -707,7 +710,7 @@ def plot_day_summary_ohlc(ax, quotes, ticksize=3,
707710
lines : list
708711
list of tuples of the lines added (one tuple per quote)
709712
"""
710-
_plot_day_summary(ax, quotes, ticksize=ticksize,
713+
return _plot_day_summary(ax, quotes, ticksize=ticksize,
711714
colorup=colorup, colordown=colordown,
712715
ochl=False)
713716

@@ -831,8 +834,9 @@ def candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
831834
warnings.warn(_warn_str.format(fun='candlestick'),
832835
mplDeprecation)
833836

834-
_candlestick(ax, quotes, width=width, colorup=colorup, colordown=colordown,
835-
alpha=alpha, ochl=True)
837+
return _candlestick(ax, quotes, width=width, colorup=colorup,
838+
colordown=colordown,
839+
alpha=alpha, ochl=True)
836840

837841

838842
def candlestick_ochl(ax, quotes, width=0.2, colorup='k', colordown='r',
@@ -870,8 +874,9 @@ def candlestick_ochl(ax, quotes, width=0.2, colorup='k', colordown='r',
870874
added and patches is a list of the rectangle patches added
871875
872876
"""
873-
_candlestick(ax, quotes, width=width, colorup=colorup, colordown=colordown,
874-
alpha=alpha, ochl=True)
877+
return _candlestick(ax, quotes, width=width, colorup=colorup,
878+
colordown=colordown,
879+
alpha=alpha, ochl=True)
875880

876881

877882
def candlestick_ohlc(ax, quotes, width=0.2, colorup='k', colordown='r',
@@ -909,8 +914,9 @@ def candlestick_ohlc(ax, quotes, width=0.2, colorup='k', colordown='r',
909914
added and patches is a list of the rectangle patches added
910915
911916
"""
912-
_candlestick(ax, quotes, width=width, colorup=colorup, colordown=colordown,
913-
alpha=alpha, ochl=False)
917+
return _candlestick(ax, quotes, width=width, colorup=colorup,
918+
colordown=colordown,
919+
alpha=alpha, ochl=False)
914920

915921

916922
def _candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',

0 commit comments

Comments
 (0)