def test_assert_same_columns(self): columns = ['a', 'b', 'c'] checks.assert_same_index(pd.DataFrame([[1, 2, 3]], columns=columns), pd.DataFrame([[1, 2, 3]], columns=columns)) try: checks.assert_same_index(pd.DataFrame([[1, 2, 3]]), pd.DataFrame([[1, 2, 3]], columns=columns)) raise Exception except: pass
def test_assert_same_index(self): index = ['a', 'b', 'c'] checks.assert_same_index(pd.Series([1, 2, 3], index=index), pd.DataFrame([1, 2, 3], index=index)) try: checks.assert_same_index(pd.Series([1, 2, 3]), pd.DataFrame([1, 2, 3], index=index)) raise Exception except: pass
def perform_init_checks(ts_list, output_list, param_list, mapper_list, name): """Perform checks on objects created by running or slicing an indicator.""" checks.assert_type(ts_list[0], (pd.Series, pd.DataFrame)) for ts in ts_list + output_list: checks.assert_same_meta(ts_list[0], ts) for params in param_list: checks.assert_same_shape(param_list[0], params) for mapper in mapper_list: checks.assert_type(mapper, pd.Series) checks.assert_same_index( reshape_fns.to_2d(ts_list[0]).iloc[0, :], mapper) checks.assert_type(name, str)
def plot_as_markers(self, ts, name=None, trace_kwargs={}, fig=None, **layout_kwargs): # pragma: no cover """Plot Series as markers. Args: ts (pandas.Series): Time series to plot markers on. !!! note Doesn't plot `ts`. name (str): Name of the signals. trace_kwargs (dict): Keyword arguments passed to `plotly.graph_objects.Scatter`. fig (plotly.graph_objects.Figure): Figure to add traces to. **layout_kwargs: Keyword arguments for layout. Example: ```py ts = pd.Series([1, 2, 3, 2, 1], index=sig.index) fig = ts.vbt.plot() sig['b'].vbt.signals.plot_as_entry_markers(ts, fig=fig) (~sig['b']).vbt.signals.plot_as_exit_markers(ts, fig=fig) ``` ![](/vectorbt/docs/img/signals_plot_as_markers.png)""" checks.assert_type(ts, pd.Series) checks.assert_same_index(self._obj, ts) if fig is None: fig = CustomFigureWidget() fig.update_layout(**layout_kwargs) if name is None: name = self._obj.name # Plot markers scatter = go.Scatter( x=ts.index[self._obj], y=ts[self._obj], mode='markers', marker=dict(symbol='circle', color=contrast_color_schema['blue'], size=7, line=dict(width=1, color=adjust_lightness( contrast_color_schema['blue']))), name=str(name), showlegend=name is not None) scatter.update(**trace_kwargs) fig.add_trace(scatter) return fig
def perform_init_checks(ts_list, output_list, param_list, mapper_list, name): """Perform checks on objects created by running or slicing an indicator.""" for ts in ts_list: checks.assert_type(ts, (pd.Series, pd.DataFrame)) ts.vbt.timeseries.validate() for i in range(1, len(ts_list) + len(output_list)): checks.assert_same_meta((ts_list + output_list)[i - 1], (ts_list + output_list)[i]) for i in range(1, len(param_list)): checks.assert_same_shape(param_list[i - 1], param_list[i]) for mapper in mapper_list: checks.assert_type(mapper, pd.Series) checks.assert_same_index( reshape_fns.to_2d(ts_list[0]).iloc[0, :], mapper) checks.assert_type(name, str)
def plot_markers(self, ts, name=None, trace_kwargs={}, fig=None, **layout_kwargs): """Plot Series as markers. Args: ts (pandas.Series): Time series to plot markers on. !!! note Doesn't plot `ts`. name (str): Name of the signals. trace_kwargs (dict): Keyword arguments passed to `plotly.graph_objects.Scatter`. fig (plotly.graph_objects.Figure): Figure to add traces to. **layout_kwargs: Keyword arguments for layout. Example: ```py fig = ts['a'].vbt.timeseries.plot() signals['a'].vbt.signals.plot_entry_markers(ts['a'], fig=fig) signals['b'].vbt.signals.plot_exit_markers(ts['a'], fig=fig) ``` ![](/vectorbt/docs/img/signals_plot_markers.png)""" checks.assert_type(ts, pd.Series) checks.assert_same_index(self._obj, ts) if fig is None: fig = DefaultFigureWidget() fig.update_layout(**layout_kwargs) if name is None: name = self._obj.name # Plot markers scatter = go.Scatter(x=ts.index[self._obj], y=ts[self._obj], mode='markers', marker=dict(size=10), name=str(name), showlegend=name is not None) scatter.update(**trace_kwargs) fig.add_trace(scatter) return fig
def test_assert_same_index(self): index = ['a', 'b', 'c'] checks.assert_same_index(pd.Series([1, 2, 3], index=index), pd.DataFrame([1, 2, 3], index=index)) with pytest.raises(Exception) as e_info: checks.assert_same_index(pd.Series([1, 2, 3]), pd.DataFrame([1, 2, 3], index=index))