Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Nov 26, 2024
1 parent 765ccdf commit 2205bb6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
14 changes: 7 additions & 7 deletions ckanext/charts/chart_builders/chartjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]:
Expand All @@ -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),
},
)

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ckanext/charts/tests/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def test_build_scatter(self, data_frame):
"engine": "plotly",
"x": "name",
"y": "age",
"size": "age",
"size_max": 10

},
data_frame,
)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit 2205bb6

Please sign in to comment.