@@ -30,21 +30,6 @@ def _check_and_prepare_data(data, config):
30
30
if not isinstance (data .index ,pd .core .indexes .datetimes .DatetimeIndex ):
31
31
raise TypeError ('Expect data.index as DatetimeIndex' )
32
32
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
-
48
33
# We will not be fully case-insensitive (since Pandas columns as NOT case-insensitive)
49
34
# but because so many people have requested it, for the default column names we will
50
35
# try both Capitalized and lower case:
@@ -57,10 +42,22 @@ def _check_and_prepare_data(data, config):
57
42
o , h , l , c , v = columns
58
43
cols = [o , h , l , c ]
59
44
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
+
64
61
opens = data [o ].values
65
62
highs = data [h ].values
66
63
lows = data [l ].values
@@ -75,6 +72,26 @@ def _check_and_prepare_data(data, config):
75
72
if not all ( isinstance (v ,(float ,int )) for v in data [col ] ):
76
73
raise ValueError ('Data for column "' + str (col )+ '" must be ALL float or int.' )
77
74
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
+
78
95
return dates , opens , highs , lows , closes , volumes
79
96
80
97
def _get_valid_plot_types (plottype = None ):
0 commit comments