Skip to content

Commit

Permalink
Warning when using methods outside param namespace (#4201)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens authored and philippjfr committed Jan 24, 2020
1 parent df1a580 commit c85b1db
Show file tree
Hide file tree
Showing 29 changed files with 96 additions and 88 deletions.
1 change: 0 additions & 1 deletion holoviews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np # noqa (API import)
import param


__version__ = str(param.version.Version(fpath=__file__, archive_commit="$Format:%h$",
reponame="holoviews"))

Expand Down
2 changes: 2 additions & 0 deletions holoviews/annotators.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def _update_links(self):

def _update_object(self, data=None):
with param.discard_events(self):
if len(self._stream.source) == 0:
self.plot[()]
self.object = self._stream.element

def _update_table(self):
Expand Down
20 changes: 10 additions & 10 deletions holoviews/core/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,16 @@ def __init__(self, spec, **params):
raise KeyError('Dimension name must only be passed as the positional argument')

if isinstance(spec, Dimension):
existing_params = dict(spec.get_param_values())
existing_params = dict(spec.param.get_param_values())
elif (spec, params.get('unit', None)) in self.presets.keys():
preset = self.presets[(str(spec), str(params['unit']))]
existing_params = dict(preset.get_param_values())
existing_params = dict(preset.param.get_param_values())
elif isinstance(spec, dict):
existing_params = spec
elif spec in self.presets:
existing_params = dict(self.presets[spec].get_param_values())
existing_params = dict(self.presets[spec].param.get_param_values())
elif (spec,) in self.presets:
existing_params = dict(self.presets[(spec,)].get_param_values())
existing_params = dict(self.presets[(spec,)].param.get_param_values())
else:
existing_params = {}

Expand Down Expand Up @@ -324,7 +324,7 @@ def clone(self, spec=None, **overrides):
Returns:
Cloned Dimension object
"""
settings = dict(self.get_param_values(), **overrides)
settings = dict(self.param.get_param_values(), **overrides)

if spec is None:
spec = (self.name, overrides.get('label', self.label))
Expand Down Expand Up @@ -382,7 +382,7 @@ def pprint_label(self):
return bytes_to_unicode(self.label) + bytes_to_unicode(unit)

def pprint(self):
changed = dict(self.get_param_values(onlychanged=True))
changed = dict(self.param.get_param_values(onlychanged=True))
if len(set([changed.get(k, k) for k in ['name','label']])) == 1:
return 'Dimension({spec})'.format(spec=repr(self.name))

Expand Down Expand Up @@ -548,7 +548,7 @@ def clone(self, data=None, shared_data=True, new_type=None, link=True,
Returns:
Cloned object
"""
params = dict(self.get_param_values())
params = dict(self.param.get_param_values())
if new_type is None:
clone_type = self.__class__
else:
Expand Down Expand Up @@ -1265,9 +1265,9 @@ def options(self, *args, **kwargs):
"Supplying both formats is not supported.")
elif args and all(isinstance(el, dict) for el in args):
if len(args) > 1:
self.warning('Only a single dictionary can be passed '
'as a positional argument. Only processing '
'the first dictionary')
self.param.warning('Only a single dictionary can be passed '
'as a positional argument. Only processing '
'the first dictionary')
options = [Options(spec, **kws) for spec,kws in args[0].items()]
elif args:
options = list(args)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/ndmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def clone(self, data=None, shared_data=True, new_type=None, link=True,
Returns:
Cloned object
"""
settings = dict(self.get_param_values())
settings = dict(self.param.get_param_values())
if settings.get('group', None) != self._group:
settings.pop('group')
if settings.get('label', None) != self._label:
Expand Down
4 changes: 2 additions & 2 deletions holoviews/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def lookup_options(obj, group, backend):
if group == 'style' and style_opts is not None:
return node.filtered(style_opts)
elif group == 'plot' and plot_class:
return node.filtered(list(plot_class.params().keys()))
return node.filtered(list(plot_class.param))
else:
return node

Expand Down Expand Up @@ -332,7 +332,7 @@ def _get_values(self):

def __call__(self, values=None, **params):
values = values if values else self.values
return self.__class__(**dict(self.get_param_values(), values=values, **params))
return self.__class__(**dict(self.param.get_param_values(), values=values, **params))


def __len__(self):
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __call__(self, obj, filter_fn=None):
if isinstance(obj,type):
return class_proxy
else:
instance_params = obj.get_param_values()
instance_params = obj.param.get_param_values()
obj_proxy = class_proxy()
filtered = {k:v for k,v in instance_params
if (k in obj_proxy.param)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def clone(self, callable=None, **overrides):
Returns:
Cloned Callable object
"""
old = {k: v for k, v in self.get_param_values()
old = {k: v for k, v in self.param.get_param_values()
if k not in ['callable', 'name']}
params = dict(old, **overrides)
callable = self.callable if callable is None else callable
Expand Down
2 changes: 2 additions & 0 deletions holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,8 @@ class ndmapping_groupby(param.ParameterizedFunction):
performance (if available).
"""

sort = param.Boolean(default=False, doc='Whether to apply a sorted groupby')

def __call__(self, ndmapping, dimensions, container_type,
group_type, sort=False, **kwargs):
try:
Expand Down
6 changes: 3 additions & 3 deletions holoviews/element/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def distribution(self, dim=None, groupby=[], **kwargs):
element = self._element
params = dict(kdims=[element.get_dimension(dim)],
label=element.label)
if element.group != element.params()['group'].default:
if element.group != element.param['group'].default:
params['group'] = element.group
return Distribution((element.dimension_values(dim),),
**dict(params, **kwargs))
Expand All @@ -67,7 +67,7 @@ def points(self, kdims=None, vdims=None, groupby=None, **kwargs):

def raster(self, kdims=None, vdims=None, groupby=None, **kwargs):
heatmap = self.heatmap(kdims, vdims, **kwargs)
return Raster(heatmap.data, **dict(self._element.get_param_values(onlychanged=True)))
return Raster(heatmap.data, **dict(self._element.param.get_param_values(onlychanged=True)))

def scatter(self, kdims=None, vdims=None, groupby=None, **kwargs):
return self(Scatter, kdims, vdims, groupby, **kwargs)
Expand All @@ -83,7 +83,7 @@ def spread(self, kdims=None, vdims=None, groupby=None, **kwargs):

def surface(self, kdims=None, vdims=None, groupby=None, **kwargs):
heatmap = self.heatmap(kdims, vdims, **kwargs)
return Surface(heatmap.data, **dict(self._table.get_param_values(onlychanged=True)))
return Surface(heatmap.data, **dict(self._table.param.get_param_values(onlychanged=True)))

def trisurface(self, kdims=None, vdims=None, groupby=None, **kwargs):
return self(TriSurface, kdims, vdims, groupby, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/element/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def clone(self, *args, **overrides):
args = args[0]
# Apply name mangling for __ attribute
pos_args = getattr(self, '_' + type(self).__name__ + '__pos_params', [])
settings = {k: v for k, v in dict(self.get_param_values(), **overrides).items()
settings = {k: v for k, v in dict(self.param.get_param_values(), **overrides).items()
if k not in pos_args[:len(args)]}
if 'id' not in settings:
settings['id'] = self.id
Expand Down
8 changes: 4 additions & 4 deletions holoviews/element/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ def compare_dimensions(cls, dim1, dim2, msg=None):
% (dim1.label, dim2.label))

# 'Deep' equality of dimension metadata (all parameters)
dim1_params = dict(dim1.get_param_values())
dim2_params = dict(dim2.get_param_values())
dim1_params = dict(dim1.param.get_param_values())
dim2_params = dict(dim2.param.get_param_values())

# Special handling of deprecated 'initial' values argument
dim1_params['values'] = [] if dim1.values=='initial' else dim1.values
Expand All @@ -312,8 +312,8 @@ def compare_dimensions(cls, dim1, dim2, msg=None):
% (set(dim1_params.keys()), set(dim2_params.keys())))

for k in dim1_params.keys():
if (dim1.params(k).__class__.__name__ == 'Callable'
and dim2.params(k).__class__.__name__ == 'Callable'):
if (dim1.param.objects('existing')[k].__class__.__name__ == 'Callable'
and dim2.param.objects('existing')[k].__class__.__name__ == 'Callable'):
continue
try: # This is needed as two lists are not compared by contents using ==
cls.assertEqual(dim1_params[k], dim2_params[k], msg=None)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/element/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def clone(self, *args, **overrides):
containing the specified args and kwargs.
"""
link = overrides.pop('link', True)
settings = dict(self.get_param_values(), **overrides)
settings = dict(self.param.get_param_values(), **overrides)
if 'id' not in settings:
settings['id'] = self.id
if not args and link:
Expand Down
4 changes: 2 additions & 2 deletions holoviews/element/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def sample(self, samples=[], **sample_values):
X, Y = samples
samples = zip(X, Y)

params = dict(self.get_param_values(onlychanged=True),
params = dict(self.param.get_param_values(onlychanged=True),
vdims=self.vdims)
params.pop('extents', None)
params.pop('bounds', None)
Expand Down Expand Up @@ -190,7 +190,7 @@ def reduce(self, dimensions=None, function=None, **reduce_map):
if oidx and hasattr(self, 'bounds'):
reduced = reduced[::-1]
data = zip(x_vals, reduced)
params = dict(dict(self.get_param_values(onlychanged=True)),
params = dict(dict(self.param.get_param_values(onlychanged=True)),
kdims=other_dimension, vdims=self.vdims)
params.pop('bounds', None)
params.pop('extents', None)
Expand Down
7 changes: 4 additions & 3 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def _process(self, element, key=None):

if overlay_aggregate.applies(element, agg_fn):
params = dict(
{p: v for p, v in self.get_param_values() if p != 'name'},
{p: v for p, v in self.param.get_param_values() if p != 'name'},
dynamic=False, **{p: v for p, v in self.p.items()
if p not in ('name', 'dynamic')})
return overlay_aggregate(element, **params)
Expand Down Expand Up @@ -492,7 +492,8 @@ def _process(self, element, key=None):
info = self._get_sampling(element, x, y, ndims)
(x_range, y_range), (xs, ys), (width, height), (xtype, ytype) = info
((x0, x1), (y0, y1)), _ = self._dt_transform(x_range, y_range, xs, ys, xtype, ytype)
agg_params = dict({k: v for k, v in dict(self.get_param_values(), **self.p).items()
agg_params = dict({k: v for k, v in dict(self.param.get_param_values(),
**self.p).items()
if k in aggregate.param},
x_range=(x0, x1), y_range=(y0, y1))
bbox = (x0, y0, x1, y1)
Expand Down Expand Up @@ -1385,7 +1386,7 @@ def _process(self, element, key=None):

unused_params = list(all_supplied_kws - all_allowed_kws)
if unused_params:
self.warning('Parameter(s) [%s] not consumed by any element rasterizer.'
self.param.warning('Parameter(s) [%s] not consumed by any element rasterizer.'
% ', '.join(unused_params))
return element

Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,14 +1281,14 @@ def __init__(self, root_model, link, source_plot, target_plot=None):
self.target_plot = target_plot
self.validate()

references = {k: v for k, v in link.get_param_values()
references = {k: v for k, v in link.param.get_param_values()
if k not in ('source', 'target', 'name')}

for sh in self.source_handles+[self.source_model]:
key = '_'.join(['source', sh])
references[key] = source_plot.handles[sh]

for p, value in link.get_param_values():
for p, value in link.param.get_param_values():
if p in ('name', 'source', 'target'):
continue
references[p] = value
Expand Down
6 changes: 3 additions & 3 deletions holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,9 @@ def get_data(self, element, ranges, style):
style_mapping = [v for k, v in style.items() if 'color' in k and
(isinstance(v, dim) or v in element)]
if style_mapping and not no_cidx and self.color_index is not None:
self.warning("Cannot declare style mapping for '%s' option "
"and declare a color_index; ignoring the color_index."
% style_mapping[0])
self.param.warning("Cannot declare style mapping for '%s' option "
"and declare a color_index; ignoring the color_index."
% style_mapping[0])
cdim = None

cvals = element.dimension_values(cdim, expanded=False) if cdim else None
Expand Down
12 changes: 6 additions & 6 deletions holoviews/plotting/bokeh/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def get_data(self, element, ranges, style):
style['line_color'] = 'white'

if not element._unique:
self.warning('HeatMap element index is not unique, ensure you '
'aggregate the data before displaying it, e.g. '
'using heatmap.aggregate(function=np.mean). '
'Duplicate index values have been dropped.')
self.param.warning('HeatMap element index is not unique, ensure you '
'aggregate the data before displaying it, e.g. '
'using heatmap.aggregate(function=np.mean). '
'Duplicate index values have been dropped.')

if self.static_source:
return {}, {'x': x, 'y': y, 'fill_color': {'field': 'zvalues', 'transform': cmapper}}, style
Expand Down Expand Up @@ -138,8 +138,8 @@ def get_data(self, element, ranges, style):
def _draw_markers(self, plot, element, marks, axis='x'):
if marks is None or self.radial:
return
self.warning('Only radial HeatMaps supports marks, to make the'
'HeatMap quads for distinguishable set a line_width')
self.param.warning('Only radial HeatMaps supports marks, to make the'
'HeatMap quads for distinguishable set a line_width')

def _init_glyphs(self, plot, element, ranges, source):
super(HeatMapPlot, self)._init_glyphs(plot, element, ranges, source)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def get_tab_title(key, frame, overlay):
title = []
if frame.label:
title.append(frame.label)
if frame.group != frame.params('group').default:
if frame.group != frame.param.objects('existing')['group'].default:
title.append(frame.group)
else:
title.append(frame.group)
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def link(self):
if self.source in self.registry:
links = self.registry[self.source]
params = {
k: v for k, v in self.get_param_values() if k != 'name'}
k: v for k, v in self.param.get_param_values() if k != 'name'}
for link in links:
link_params = {
k: v for k, v in link.get_param_values() if k != 'name'}
k: v for k, v in link.param.get_param_values() if k != 'name'}
if (type(link) is type(self) and link.source is self.source
and link.target is self.target and params == link_params):
return
Expand Down
14 changes: 7 additions & 7 deletions holoviews/plotting/mpl/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def _compute_ticks(self, element, xvals, yvals, xfactors, yfactors):
def _draw_markers(self, ax, element, marks, values, factors, axis='x'):
if marks is None or self.radial:
return
self.warning('Only radial HeatMaps supports marks, to make the'
'HeatMap quads more distinguishable set linewidths'
'to a non-zero value.')
self.param.warning('Only radial HeatMaps supports marks, to make the'
'HeatMap quads more distinguishable set linewidths'
'to a non-zero value.')


def init_artists(self, ax, plot_args, plot_kwargs):
Expand All @@ -151,10 +151,10 @@ def get_data(self, element, ranges, style):
aggregate = element.gridded

if not element._unique:
self.warning('HeatMap element index is not unique, ensure you '
'aggregate the data before displaying it, e.g. '
'using heatmap.aggregate(function=np.mean). '
'Duplicate index values have been dropped.')
self.param.warning('HeatMap element index is not unique, ensure you '
'aggregate the data before displaying it, e.g. '
'using heatmap.aggregate(function=np.mean). '
'Duplicate index values have been dropped.')

data = aggregate.dimension_values(2, flat=False)
data = np.ma.array(data, mask=np.logical_not(np.isfinite(data)))
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/mpl/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ def _create_subplots(self, layout, positions, layout_dimensions, ranges, axes={}
override_opts = {}
sublabel_opts = {}
if pos == 'main':
own_params = self.get_param_values(onlychanged=True)
own_params = self.param.get_param_values(onlychanged=True)
sublabel_opts = {k: v for k, v in own_params
if 'sublabel_' in k}
elif pos == 'right':
Expand Down
Loading

0 comments on commit c85b1db

Please sign in to comment.