Kozea / Kozea/pygal

TypeError: unsupported operand type(s) for /: 'decimal.Decimal' and 'float'

Open
#457 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.8k
Forks
419
PR merge metrics
No merged PRs in 30d

Description

Using v2.4.0 I'm getting a `TypeError` when data points are `decimal.Decimal` and calling `render_to_png`.

```
File "/opt/app/current/app/models/goals.py", line 575, in to_png
return utils.optimize_png(chart.render_to_png())
File "/opt/app/current/venv/lib/python3.6/site-packages/pygal/graph/public.py", line 120, in render_to_png
bytestring=self.render(**kwargs), write_to=filename, dpi=dpi)
File "/opt/app/current/venv/lib/python3.6/site-packages/pygal/graph/public.py", line 52, in render
self.setup(**kwargs)
File "/opt/app/current/venv/lib/python3.6/site-packages/pygal/graph/base.py", line 217, in setup
self._draw()
File "/opt/app/current/venv/lib/python3.6/site-packages/pygal/graph/graph.py", line 926, in _draw
self._compute_y_labels()
File "/opt/app/current/venv/lib/python3.6/site-packages/pygal/graph/graph.py", line 853, in _compute_y_labels
self.order_min, self.min_scale, self.max_scale
File "/opt/app/current/venv/lib/python3.6/site-packages/pygal/util.py", line 171, in compute_scale
while (max_ - min_) / step > max_scale:
TypeError: unsupported operand type(s) for /: 'decimal.Decimal' and 'float'
```

Contributor guide

Open the contributing guide

Research direction

Start in pygal/util.py at compute_scale, where the traceback shows Decimal values being divided by a float during render_to_png. Reproduce the failure with decimal.Decimal data and a PNG render; done means the chart renders without this TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.