@@ -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
8097def  _get_valid_plot_types (plottype = None ):
0 commit comments