1616 tomato as BEAR_COLOR
1717)
1818from bokeh .plotting import figure as _figure
19- from bokeh .models import (
19+ from bokeh .models import ( # type: ignore
2020 CrosshairTool ,
2121 CustomJS ,
2222 ColumnDataSource ,
2525 HoverTool ,
2626 Range1d ,
2727 DatetimeTickFormatter ,
28- FuncTickFormatter ,
2928 WheelZoomTool ,
3029 LinearColorMapper ,
3130)
31+ try :
32+ from bokeh .models import CustomJSTickFormatter
33+ except ImportError : # Bokeh < 3.0
34+ from bokeh .models import FuncTickFormatter as CustomJSTickFormatter # type: ignore
3235from bokeh .io import output_notebook , output_file , show
3336from bokeh .io .state import curstate
3437from bokeh .layouts import gridplot
@@ -85,7 +88,7 @@ def colorgen():
8588def lightness (color , lightness = .94 ):
8689 rgb = np .array ([color .r , color .g , color .b ]) / 255
8790 h , _ , s = rgb_to_hls (* rgb )
88- rgb = np .array (hls_to_rgb (h , lightness , s )) * 255
91+ rgb = np .array (hls_to_rgb (h , lightness , s )) * 255.
8992 return RGB (* rgb )
9093
9194
@@ -138,10 +141,10 @@ def _weighted_returns(s, trades=trades):
138141 return ((df ['Size' ].abs () * df ['ReturnPct' ]) / df ['Size' ].abs ().sum ()).sum ()
139142
140143 def _group_trades (column ):
141- def f (s , new_index = df .index .astype ( np . int64 ), bars = trades [column ]):
144+ def f (s , new_index = pd . Index ( df .index .view ( int ) ), bars = trades [column ]):
142145 if s .size :
143146 # Via int64 because on pandas recently broken datetime
144- mean_time = int (bars .loc [s .index ].view ('i8' ).mean ())
147+ mean_time = int (bars .loc [s .index ].view (int ).mean ())
145148 new_bar_idx = new_index .get_loc (mean_time , method = 'nearest' )
146149 return new_bar_idx
147150 return f
@@ -209,19 +212,19 @@ def plot(*, results: pd.Series,
209212 new_bokeh_figure = partial (
210213 _figure ,
211214 x_axis_type = 'linear' ,
212- plot_width = plot_width ,
213- plot_height = 400 ,
215+ width = plot_width ,
216+ height = 400 ,
214217 tools = "xpan,xwheel_zoom,box_zoom,undo,redo,reset,save" ,
215218 active_drag = 'xpan' ,
216219 active_scroll = 'xwheel_zoom' )
217220
218221 pad = (index [- 1 ] - index [0 ]) / 20
219222
220- fig_ohlc = new_bokeh_figure (
221- x_range = Range1d ( index [ 0 ], index [ - 1 ] ,
222- min_interval = 10 ,
223- bounds = ( index [0 ] - pad ,
224- index [ - 1 ] + pad )) if index . size > 1 else None )
223+ _kwargs = dict ( x_range = Range1d ( index [ 0 ], index [ - 1 ],
224+ min_interval = 10 ,
225+ bounds = ( index [ 0 ] - pad ,
226+ index [- 1 ] + pad ))) if index . size > 1 else {}
227+ fig_ohlc = new_bokeh_figure ( ** _kwargs )
225228 figs_above_ohlc , figs_below_ohlc = [], []
226229
227230 source = ColumnDataSource (df )
@@ -242,10 +245,10 @@ def plot(*, results: pd.Series,
242245 trades_cmap = factor_cmap ('returns_positive' , colors_darker , ['0' , '1' ])
243246
244247 if is_datetime_index :
245- fig_ohlc .xaxis .formatter = FuncTickFormatter (
248+ fig_ohlc .xaxis .formatter = CustomJSTickFormatter (
246249 args = dict (axis = fig_ohlc .xaxis [0 ],
247- formatter = DatetimeTickFormatter (days = [ '%d %b' , '%a %d' ] ,
248- months = [ '%m/%Y' , "%b'%y" ] ),
250+ formatter = DatetimeTickFormatter (days = '%a, %d %b' ,
251+ months = '%m/%Y' ),
249252 source = source ),
250253 code = '''
251254this.labels = this.labels || formatter.doFormat(ticks
@@ -254,7 +257,7 @@ def plot(*, results: pd.Series,
254257return this.labels[index] || "";
255258 ''' )
256259
257- NBSP = '\N{NBSP} ' * 4
260+ NBSP = '\N{NBSP} ' * 4 # noqa: E999
258261 ohlc_extreme_values = df [['High' , 'Low' ]].copy (deep = False )
259262 ohlc_tooltips = [
260263 ('x, y' , NBSP .join (('$index' ,
@@ -266,7 +269,7 @@ def plot(*, results: pd.Series,
266269 ('Volume' , '@Volume{0,0}' )]
267270
268271 def new_indicator_figure (** kwargs ):
269- kwargs .setdefault ('plot_height ' , 90 )
272+ kwargs .setdefault ('height ' , 90 )
270273 fig = new_bokeh_figure (x_range = fig_ohlc .x_range ,
271274 active_scroll = 'xwheel_zoom' ,
272275 active_drag = 'xpan' ,
@@ -331,7 +334,7 @@ def _plot_equity_section(is_return=False):
331334 source .add (equity , source_key )
332335 fig = new_indicator_figure (
333336 y_axis_label = yaxis_label ,
334- ** ({} if plot_drawdown else dict (plot_height = 110 )))
337+ ** ({} if plot_drawdown else dict (height = 110 )))
335338
336339 # High-watermark drawdown dents
337340 fig .patch ('index' , 'equity_dd' ,
@@ -622,7 +625,7 @@ def __eq__(self, other):
622625 if plot_volume :
623626 custom_js_args .update (volume_range = fig_volume .y_range )
624627
625- fig_ohlc .x_range .js_on_change ('end' , CustomJS (args = custom_js_args ,
628+ fig_ohlc .x_range .js_on_change ('end' , CustomJS (args = custom_js_args , # type: ignore
626629 code = _AUTOSCALE_JS_CALLBACK ))
627630
628631 plots = figs_above_ohlc + [fig_ohlc ] + figs_below_ohlc
@@ -647,7 +650,7 @@ def __eq__(self, other):
647650
648651 f .add_tools (linked_crosshair )
649652 wheelzoom_tool = next (wz for wz in f .tools if isinstance (wz , WheelZoomTool ))
650- wheelzoom_tool .maintain_focus = False
653+ wheelzoom_tool .maintain_focus = False # type: ignore
651654
652655 kwargs = {}
653656 if plot_width is None :
@@ -659,7 +662,7 @@ def __eq__(self, other):
659662 toolbar_location = 'right' ,
660663 toolbar_options = dict (logo = None ),
661664 merge_tools = True ,
662- ** kwargs
665+ ** kwargs # type: ignore
663666 )
664667 show (fig , browser = None if open_browser else 'none' )
665668 return fig
@@ -694,8 +697,8 @@ def plot_heatmaps(heatmap: pd.Series, agg: Union[Callable, str], ncols: int,
694697 y_range = level2 ,
695698 x_axis_label = name1 ,
696699 y_axis_label = name2 ,
697- plot_width = plot_width // ncols ,
698- plot_height = plot_width // ncols ,
700+ width = plot_width // ncols ,
701+ height = plot_width // ncols ,
699702 tools = 'box_zoom,reset,save' ,
700703 tooltips = [(name1 , '@' + name1 ),
701704 (name2 , '@' + name2 ),
@@ -716,7 +719,7 @@ def plot_heatmaps(heatmap: pd.Series, agg: Union[Callable, str], ncols: int,
716719 plots .append (fig )
717720
718721 fig = gridplot (
719- plots ,
722+ plots , # type: ignore
720723 ncols = ncols ,
721724 toolbar_options = dict (logo = None ),
722725 toolbar_location = 'above' ,
0 commit comments