Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d5fff66

Browse files
Merge pull request #567 from DanielGoldfarb/master
Check for whitespace in column names when column not found.
2 parents 8d46383 + c7005ab commit d5fff66

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

‎src/mplfinance/_arg_validators.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,6 @@ def _check_and_prepare_data(data, config):
3030
if not isinstance(data.index,pd.core.indexes.datetimes.DatetimeIndex):
3131
raise TypeError('Expect data.index as DatetimeIndex')
3232

33-
if (len(data.index) > config['warn_too_much_data'] and
34-
(config['type']=='candle' or config['type']=='ohlc' or config['type']=='hollow_and_filled')
35-
):
36-
warnings.warn('\n\n ================================================================= '+
37-
'\n\n WARNING: YOU ARE PLOTTING SO MUCH DATA THAT IT MAY NOT BE'+
38-
'\n POSSIBLE TO SEE DETAILS (Candles, Ohlc-Bars, Etc.)'+
39-
'\n For more information see:'+
40-
'\n - https://github.com/matplotlib/mplfinance/wiki/Plotting-Too-Much-Data'+
41-
'\n '+
42-
'\n TO SILENCE THIS WARNING, set `type=\'line\'` in `mpf.plot()`'+
43-
'\n OR set kwarg `warn_too_much_data=N` where N is an integer '+
44-
'\n LARGER than the number of data points you want to plot.'+
45-
'\n\n ================================================================ ',
46-
category=UserWarning)
47-
4833
# We will not be fully case-insensitive (since Pandas columns as NOT case-insensitive)
4934
# but because so many people have requested it, for the default column names we will
5035
# try both Capitalized and lower case:
@@ -57,10 +42,22 @@ def _check_and_prepare_data(data, config):
5742
o, h, l, c, v = columns
5843
cols = [o, h, l, c]
5944

60-
if config['tz_localize']:
61-
dates = mdates.date2num(data.index.tz_localize(None).to_pydatetime())
62-
else: # Just in case someone was depending on this bug (Issue 236)
63-
dates = mdates.date2num(data.index.to_pydatetime())
45+
if config['volume'] != False:
46+
expect_cols = columns
47+
else:
48+
expect_cols = cols
49+
50+
for col in expect_cols:
51+
if col not in data.columns:
52+
for dc in data.columns:
53+
if dc.strip() != dc:
54+
warnings.warn('\n ================================================================= '+
55+
'\n Input DataFrame column name "'+dc+'" '+
56+
'\n contains leading and/or trailing whitespace.',category=UserWarning)
57+
raise ValueError('Column "'+col+'" NOT FOUND in Input DataFrame!'+
58+
'\n CHECK that your column names are correct AND/OR'+
59+
'\n CHECK for leading or trailing blanks in your column names.')
60+
6461
opens = data[o].values
6562
highs = data[h].values
6663
lows = data[l].values
@@ -75,6 +72,26 @@ def _check_and_prepare_data(data, config):
7572
if not all( isinstance(v,(float,int)) for v in data[col] ):
7673
raise ValueError('Data for column "'+str(col)+'" must be ALL float or int.')
7774

75+
if config['tz_localize']:
76+
dates = mdates.date2num(data.index.tz_localize(None).to_pydatetime())
77+
else: # Just in case someone was depending on this bug (Issue 236)
78+
dates = mdates.date2num(data.index.to_pydatetime())
79+
80+
if (len(data.index) > config['warn_too_much_data'] and
81+
(config['type']=='candle' or config['type']=='ohlc' or config['type']=='hollow_and_filled')
82+
):
83+
warnings.warn('\n\n ================================================================= '+
84+
'\n\n WARNING: YOU ARE PLOTTING SO MUCH DATA THAT IT MAY NOT BE'+
85+
'\n POSSIBLE TO SEE DETAILS (Candles, Ohlc-Bars, Etc.)'+
86+
'\n For more information see:'+
87+
'\n - https://github.com/matplotlib/mplfinance/wiki/Plotting-Too-Much-Data'+
88+
'\n '+
89+
'\n TO SILENCE THIS WARNING, set `type=\'line\'` in `mpf.plot()`'+
90+
'\n OR set kwarg `warn_too_much_data=N` where N is an integer '+
91+
'\n LARGER than the number of data points you want to plot.'+
92+
'\n\n ================================================================ ',
93+
category=UserWarning)
94+
7895
return dates, opens, highs, lows, closes, volumes
7996

8097
def _get_valid_plot_types(plottype=None):

‎src/mplfinance/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version_info = (0, 12, 9, 'beta', 4)
1+
version_info = (0, 12, 9, 'beta', 5)
22

33
_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}
44

‎src/mplfinance/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ def _auto_secondary_y( panels, panid, ylo, yhi ):
12351235

12361236
def _valid_addplot_kwargs():
12371237

1238-
valid_linestyles = ('-','solid','--','dashed','-.','dashdot','.','dotted',None,' ','')
1238+
valid_linestyles = ('-','solid','--','dashed','-.','dashdot',':','dotted',None,' ','')
12391239
valid_types = ('line','scatter','bar', 'ohlc', 'candle','step')
12401240
valid_stepwheres = ('pre','post','mid')
12411241
valid_edgecolors = ('face', 'none', None)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /