diff --git a/holoviews/operation/element.py b/holoviews/operation/element.py index 33a00def94..35dbfb0a5f 100644 --- a/holoviews/operation/element.py +++ b/holoviews/operation/element.py @@ -786,6 +786,8 @@ def _process(self, element, key=None): hist_range = (0, 1) steps = self.p.num_bins + 1 start, end = hist_range + if isinstance(start, str) or isinstance(end, str) or isinstance(steps, str): + raise ValueError("Categorical data found. Cannot create histogram from categorical data.") if is_datetime: start, end = dt_to_int(start, 'ns'), dt_to_int(end, 'ns') if self.p.log: diff --git a/holoviews/tests/operation/test_operation.py b/holoviews/tests/operation/test_operation.py index 0b1101dc3d..87a6dd8032 100644 --- a/holoviews/tests/operation/test_operation.py +++ b/holoviews/tests/operation/test_operation.py @@ -1,5 +1,6 @@ import datetime as dt from unittest import skipIf +import pytest import numpy as np import pandas as pd @@ -256,6 +257,12 @@ def test_histogram_operation_pd_period(self): hist = Histogram(hist_data, kdims='Date', vdims=('Date_frequency', 'Frequency')) self.assertEqual(op_hist, hist) + def test_histogram_categorical(self): + series = Dataset(pd.Series(['A', 'B', 'C'])) + kwargs = {'bin_range': ('A', 'C'), 'normed': False, 'cumulative': False, 'num_bins': 3} + with pytest.raises(ValueError): + histogram(series, **kwargs) + def test_points_histogram_weighted(self): points = Points([float(i) for i in range(10)]) op_hist = histogram(points, num_bins=3, weight_dimension='y', normed=True)