Skip to content

Commit

Permalink
Raise when calling Dimension with invalid type
Browse files Browse the repository at this point in the history
Two helper functions no longer need to raise such an exception.
  • Loading branch information
stanwest committed Jun 8, 2022
1 parent 28b7cc2 commit a849a7c
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions holoviews/core/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,8 @@ def asdim(dimension):
A Dimension object constructed from the dimension spec. No
copy is performed if the input is already a Dimension.
"""
if isinstance(dimension, Dimension):
return dimension
elif isinstance(dimension, (tuple, dict, str)):
return Dimension(dimension)
else:
raise ValueError('%s type could not be interpreted as Dimension. '
'Dimensions must be declared as a string, tuple, '
'dictionary or Dimension type.')
return dimension if isinstance(dimension, Dimension) else Dimension(dimension)


def dimension_name(dimension):
"""Return the Dimension.name for a dimension-like object.
Expand Down Expand Up @@ -118,11 +112,6 @@ def process_dimensions(kdims, vdims):
"specified as tuples, strings, dictionaries or Dimension "
"instances, not a %s type. Ensure you passed the data as the "
"first argument." % (group, type(dims).__name__))
for dim in dims:
if not isinstance(dim, (tuple, str, Dimension, dict)):
raise ValueError('Dimensions must be defined as a tuple, '
'string, dictionary or Dimension instance, '
'found a %s type.' % type(dim).__name__)
dimensions[group] = [asdim(d) for d in dims]
return dimensions

Expand Down Expand Up @@ -274,6 +263,12 @@ def __init__(self, spec, **params):
raise ValueError(
'Dimension specified as a dict must contain a "name" key'
) from exc
else:
raise ValueError(
'%s type could not be interpreted as Dimension. Dimensions must be '
'declared as a string, tuple, dictionary or Dimension type.'
% type(spec).__name__
)
all_params.update(params)

if not all_params['name']:
Expand Down

0 comments on commit a849a7c

Please sign in to comment.