From 2205bb6b3836e3d05084e799cc5a13439510c71d Mon Sep 17 00:00:00 2001 From: mutantsan Date: Tue, 26 Nov 2024 11:30:07 +0200 Subject: [PATCH] fix: fix tests --- .github/workflows/test.yml | 7 ++++--- ckanext/charts/chart_builders/chartjs.py | 14 +++++++------- ckanext/charts/tests/test_builders.py | 3 +++ pyproject.toml | 2 ++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ee5ebd4..ac1286c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,12 +4,13 @@ jobs: test: runs-on: ubuntu-latest container: - image: ckan/ckan-dev:2.10.3 + image: ckan/ckan-dev:2.10-py3.10 + options: --user root services: solr: image: ckan/ckan-solr:2.10 postgres: - image: ckan/ckan-postgres-dev:2.9 + image: ckan/ckan-postgres-dev:2.10 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres @@ -30,7 +31,7 @@ jobs: # Install any extra requirements your extension has here (dev requirements, other extensions etc) run: | pip install --upgrade pip - pip install -e '.[dev]' + pip install -e '.[dev, pyarrow]' - name: Setup extension # Extra initialization steps run: | diff --git a/ckanext/charts/chart_builders/chartjs.py b/ckanext/charts/chart_builders/chartjs.py index d5b1456..37eb8a5 100644 --- a/ckanext/charts/chart_builders/chartjs.py +++ b/ckanext/charts/chart_builders/chartjs.py @@ -360,7 +360,7 @@ def to_json(self) -> str: } dataset_data = [] - max_size = self.df[self.settings["size"]].max() + size_max = self.df[self.settings["size"]].max() for _, data_series in self.df.iterrows(): for field in [self.settings["y"]]: @@ -370,7 +370,7 @@ def to_json(self) -> str: data_series[self.settings["x"]], ), "y": self.convert_to_native_types(data_series[field]), - "r": self._calculate_bubble_radius(data_series, max_size), + "r": self._calculate_bubble_radius(data_series, size_max), }, ) @@ -381,22 +381,22 @@ def to_json(self) -> str: return json.dumps(self._configure_date_axis(data)) - def _calculate_bubble_radius(self, data_series: pd.Series, max_size: int) -> int: + def _calculate_bubble_radius(self, data_series: pd.Series, size_max: int) -> int: """Calculate bubble radius based on the size column""" size_column: str = self.settings["size"] - # Handle cases where max_size is zero or NaN values are present + # Handle cases where size_max is zero or NaN values are present # or the column is not numeric try: - pd.to_numeric(max_size) + pd.to_numeric(size_max) except ValueError as e: raise ChartBuildError(f"Column '{size_column}' is not numeric") from e - if max_size == 0 or np.isnan(max_size): + if size_max == 0 or np.isnan(size_max): bubble_radius = self.min_bubble_radius else: data_series_size = np.nan_to_num(data_series[size_column], nan=0) - bubble_radius = (data_series_size / max_size) * 30 + bubble_radius = (data_series_size / size_max) * 30 if bubble_radius < self.min_bubble_radius: bubble_radius = self.min_bubble_radius diff --git a/ckanext/charts/tests/test_builders.py b/ckanext/charts/tests/test_builders.py index 9085e72..ce93ee7 100644 --- a/ckanext/charts/tests/test_builders.py +++ b/ckanext/charts/tests/test_builders.py @@ -85,6 +85,9 @@ def test_build_scatter(self, data_frame): "engine": "plotly", "x": "name", "y": "age", + "size": "age", + "size_max": 10 + }, data_frame, ) diff --git a/pyproject.toml b/pyproject.toml index 37bdf4d..9624a44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,8 @@ dependencies = [ "pandas>=2.0.0,<=2.1.4", "plotly>=5.21.0,<6.0.0", "redis>=5.0.0,<6.0.0", + "openpyxl>=3.1.2,<4.0.0", + "xlrd>=2.0.1,<3.0.0", "ckanext-scheming", ] license = {text = "AGPL"}