diff --git a/ckanext/charts/chart_builders/plotly.py b/ckanext/charts/chart_builders/plotly.py index 9bce079..df5bc9b 100644 --- a/ckanext/charts/chart_builders/plotly.py +++ b/ckanext/charts/chart_builders/plotly.py @@ -241,10 +241,11 @@ def build_scatter_chart(self) -> Any: if self.settings.get("skip_null_values"): self.df = self.df.loc[self.df[self.settings["y"]] != 0] - if self.df[self.settings["size"]].dtype not in ["int64", "float64"]: + size_column = self.df[self.settings.get("size", self.df.columns[0])] + is_numeric = pd.api.types.is_numeric_dtype(size_column) + if not is_numeric: raise exception.ChartBuildError( - """The 'size' source should be a field of positive integer - or float type.""", + "The 'Size' source should be a field of numeric type.", ) fig = px.scatter( diff --git a/ckanext/charts/tests/test_builders.py b/ckanext/charts/tests/test_builders.py index ce93ee7..a000479 100644 --- a/ckanext/charts/tests/test_builders.py +++ b/ckanext/charts/tests/test_builders.py @@ -86,8 +86,7 @@ def test_build_scatter(self, data_frame): "x": "name", "y": "age", "size": "age", - "size_max": 10 - + "size_max": 100, }, data_frame, )