def clear_options(self): # Clear global options.. Store.options(val=OptionTree(groups=['plot', 'style']), backend='matplotlib') Store.options(val=OptionTree(groups=['plot', 'style']), backend='bokeh') # ... and custom options Store.custom_options({}, backend='matplotlib') Store.custom_options({}, backend='bokeh')
def test_optiontree_dict_setter_getter(self): options = OptionTree(groups=['group1', 'group2']) opts1 = Options(kw1='value1') opts2 = Options(kw2='value2') options.MyType = {'group1': opts1, 'group2': opts2} self.assertEqual(options.MyType['group1'], opts1) self.assertEqual(options.MyType['group1'].options, {'kw1': 'value1'}) self.assertEqual(options.MyType['group2'], opts2) self.assertEqual(options.MyType['group2'].options, {'kw2': 'value2'})
def setUp(self): if 'bokeh' not in Store.renderers: raise SkipTest( "Cross background tests assumes bokeh is available.") self.store_mpl = OptionTree(sorted( Store.options(backend='matplotlib').items()), groups=['style', 'plot', 'norm']) self.store_bokeh = OptionTree(sorted( Store.options(backend='bokeh').items()), groups=['style', 'plot', 'norm']) self.clear_options() super(TestCrossBackendOptions, self).setUp()
def setUp(self): if 'matplotlib' not in Store.renderers: raise SkipTest("Cross background tests assumes matplotlib is available") if 'bokeh' not in Store.renderers: raise SkipTest("Cross background tests assumes bokeh is available.") # Some tests require that plotly isn't loaded self.plotly_options = Store._options.pop('plotly', None) self.store_mpl = OptionTree(sorted(Store.options(backend='matplotlib').items()), groups=['style', 'plot', 'norm']) self.store_bokeh = OptionTree(sorted(Store.options(backend='bokeh').items()), groups=['style', 'plot', 'norm']) self.clear_options() super(TestCrossBackendOptions, self).setUp()
def setUp(self): try: import xarray as xr except: raise SkipTest('Xarray not available') self.backend = 'bokeh' hv.extension(self.backend) Store.current_backend = self.backend self.store_copy = OptionTree(sorted(Store.options().items()), groups=Options._option_groups) import hvplot.xarray # noqa self.da = xr.DataArray( data=np.arange(16).reshape((2, 2, 2, 2)), coords={ 'time': [0, 1], 'y': [0, 1], 'x': [0, 1], 'band': [0, 1] }, dims=['time', 'y', 'x', 'band'], name='test', ) da2 = xr.DataArray(data=np.arange(27).reshape((3, 3, 3)), coords={ 'y': [0, 1, 2], 'x': [0, 1, 2] }, dims=['y', 'x', 'other'], name='test2') self.ds1 = xr.Dataset(dict(foo=self.da)) self.ds2 = xr.Dataset(dict(foo=self.da, bar=da2))
def test_optiontree_inheritance(self): options = OptionTree(groups=['group1', 'group2']) opts1 = Options(kw1='value1') opts2 = Options(kw2='value2') options.MyType = {'group1':opts1, 'group2':opts2} opts3 = Options(kw3='value3') opts4 = Options(kw4='value4') options.MyType.Child = {'group1':opts3, 'group2':opts4} self.assertEqual(options.MyType.Child.options('group1').kwargs, {'kw1':'value1', 'kw3':'value3'}) self.assertEqual(options.MyType.Child.options('group2').kwargs, {'kw2':'value2', 'kw4':'value4'})
def test_custom_magic_to_default_inheritance(self): """ Checks customs inheritance backs off to default tree correctly simulating the %%opts cell magic. """ if 'matplotlib' not in Store.renderers: raise SkipTest("Custom magic inheritance test requires matplotlib") options = self.initialize_option_tree() options.Image.A.B = Options('style', alpha=0.2) obj = Image(np.random.rand(10, 10), group='A', label='B') # Before customizing... expected_obj = { 'alpha': 0.2, 'cmap': 'hot', 'interpolation': 'nearest' } obj_lookup = Store.lookup_options('matplotlib', obj, 'style') self.assertEqual(obj_lookup.kwargs, expected_obj) custom_tree = { 0: OptionTree(groups=Options._option_groups, style={'Image': dict(clims=(0, 0.5))}) } Store._custom_options['matplotlib'] = custom_tree obj.id = 0 # Manually set the id to point to the tree above # Customize this particular object expected_custom_obj = dict(clims=(0, 0.5), **expected_obj) custom_obj_lookup = Store.lookup_options('matplotlib', obj, 'style') self.assertEqual(custom_obj_lookup.kwargs, expected_custom_obj)
def setUp(self): if 'matplotlib' not in Store.renderers: raise SkipTest('Matplotlib backend not available.') self.store_copy = OptionTree(sorted(Store.options().items()), groups=Options._option_groups) self.backend = 'matplotlib' Store.current_backend = self.backend super(TestStoreInheritanceDynamic, self).setUp()
def setUp(self): if 'matplotlib' not in Store.renderers: raise SkipTest('Matplotlib backend not available.') self.store_copy = OptionTree(sorted(Store.options().items()), groups=Options._option_groups) self.backend = 'matplotlib' Store.set_current_backend(self.backend) super(TestOptsMethod, self).setUp()
def setUp(self): options = OptionTree(groups={'group': Options()}) self.opts1 = Options('group', kw1='value1') self.opts2 = Options('group', kw2='value2') self.opts3 = Options('group', kw3='value3') self.opts4 = Options('group', kw4='value4') self.opts5 = Options('group', kw5='value5') self.opts6 = Options('group', kw6='value6') options.MyType = self.opts1 options.XType = self.opts2 options.MyType.Foo = self.opts3 options.MyType.Bar = self.opts4 options.XType.Foo = self.opts5 options.XType.Bar = self.opts6 self.options = options
def test_optiontree_inheritance(self): if 'matplotlib' not in Store.renderers: raise SkipTest("General to specific option test requires matplotlib") options = OptionTree(groups=['group1', 'group2']) opts1 = Options(kw1='value1') opts2 = Options(kw2='value2') options.MyType = {'group1':opts1, 'group2':opts2} opts3 = Options(kw3='value3') opts4 = Options(kw4='value4') options.MyType.Child = {'group1':opts3, 'group2':opts4} self.assertEqual(options.MyType.Child.options('group1').kwargs, {'kw1':'value1', 'kw3':'value3'}) self.assertEqual(options.MyType.Child.options('group2').kwargs, {'kw2':'value2', 'kw4':'value4'})
def setUp(self): self.store_copy = OptionTree(sorted(Store.options().items()), groups=['style', 'plot', 'norm']) self.backend = 'matplotlib' Store.current_backend = self.backend Store.options(val=OptionTree(groups=['plot', 'style'])) options = Store.options() self.default_plot = dict(plot1='plot1', plot2='plot2') options.Histogram = Options('plot', **self.default_plot) self.default_style = dict(style1='style1', style2='style2') options.Histogram = Options('style', **self.default_style) data = [np.random.normal() for i in range(10000)] frequencies, edges = np.histogram(data, 20) self.hist = Histogram(frequencies, edges) super(TestStoreInheritance, self).setUp()
def setUp(self): options = OptionTree(groups=['group']) self.opts1 = Options('group', kw1='value1') self.opts2 = Options('group', kw2='value2') self.opts3 = Options('group', kw3='value3') self.opts4 = Options('group', kw4='value4') self.opts5 = Options('group', kw5='value5') self.opts6 = Options('group', kw6='value6') options.MyType = self.opts1 options.XType = self.opts2 options.MyType.Foo = self.opts3 options.MyType.Bar = self.opts4 options.XType.Foo = self.opts5 options.XType.Bar = self.opts6 self.options = options self.original_options = Store.options() Store.options(val=OptionTree(groups=['group']))
def test_optiontree_inheritance_flipped(self): """ Tests for ordering problems manifested in issue #93 """ options = OptionTree(groups=['group1', 'group2']) opts3 = Options(kw3='value3') opts4 = Options(kw4='value4') options.MyType.Child = {'group1':opts3, 'group2':opts4} opts1 = Options(kw1='value1') opts2 = Options(kw2='value2') options.MyType = {'group1':opts1, 'group2':opts2} self.assertEqual(options.MyType.Child.options('group1').kwargs, {'kw1':'value1', 'kw3':'value3'}) self.assertEqual(options.MyType.Child.options('group2').kwargs, {'kw2':'value2', 'kw4':'value4'})
def register_custom(cls, objtype, backend, custom_plot=[], custom_style=[]): groups = Options._option_groups if backend not in Store._options: Store._options[backend] = OptionTree([], groups=groups) Store._custom_options[backend] = {} name = objtype.__name__ style_opts = Keywords(['style_opt1', 'style_opt2']+custom_style, name) plot_opts = Keywords(['plot_opt1', 'plot_opt2']+custom_plot, name) opt_groups = {'plot': Options(allowed_keywords=plot_opts), 'style': Options(allowed_keywords=style_opts)} Store._options[backend][name] = opt_groups
def setUp(self): try: import pandas as pd except: raise SkipTest('Pandas not available') self.backend = 'bokeh' hv.extension(self.backend) Store.current_backend = self.backend self.store_copy = OptionTree(sorted(Store.options().items()), groups=Options._option_groups) patch('pandas') self.df = pd.DataFrame([[1, 2, 'A', 0.1], [3, 4, 'B', 0.2], [5, 6, 'C', 0.3]], columns=['x', 'y', 'category', 'number'])
def setUp(self): self.store_copy = OptionTree(sorted(Store.options().items()), groups=['style', 'plot', 'norm']) self.backend = 'matplotlib' Store.set_current_backend(self.backend) super(TestOptsMethod, self).setUp()
def setUp(self): self.backend = Store.current_backend Store.current_backend = 'matplotlib' self.store_copy = OptionTree(sorted(Store.options().items()), groups=Options._option_groups) super(TestOptsUtil, self).setUp()
def setUp(self): self.store_copy = OptionTree(sorted(Store.options().items()), groups=['style', 'plot', 'norm']) self.backend = 'matplotlib' super(TestOptsUtil, self).setUp()
def test_optiontree_init(self): OptionTree(groups={'group1': Options(), 'group2': Options()})
def test_optiontree_setter_getter(self): options = OptionTree(groups=['group1', 'group2']) opts = Options('group1', kw1='value') options.MyType = opts self.assertEqual(options.MyType['group1'], opts) self.assertEqual(options.MyType['group1'].options, {'kw1': 'value'})
def test_optiontree_init_2(self): OptionTree(groups=['group1', 'group2'])
def setUp(self): self.store_copy = OptionTree(sorted(Store.options().items()), groups=['style', 'plot', 'norm']) self.backend = 'matplotlib' Store.current_backend = self.backend super(TestStoreInheritanceDynamic, self).setUp()
def initialize_option_tree(self): Store.options(val=OptionTree(groups=['plot', 'style'])) options = Store.options() options.Image = Options('style', cmap='hot', interpolation='nearest') return options