Kozea / Kozea/pygal

render_to_file hangs forever if the values to plot is a float with many digits after the decimal

Open
#479 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

So I have a use case where the x-axis is the date and y axis is a float number (derived from some math computation).
So for example
{'key_1': [(datetime.datetime(2019, 11, 4, 0, 0), 221.03), (datetime.datetime(2019, 11, 1, 0, 0), 221.03)], 'key_2': [(datetime.datetime(2019, 11, 4, 0, 0), 221.03000000000006), (datetime.datetime(2019, 11, 1, 0, 0), 221.0300000000001)]}

Here x_axis --> (datetime.datetime(2019, 11, 4, 0, 0) & y_axis --> 221.03 and so on

When I render "key_1" to a file it works fine, but when I render "key_2" it just hangs forever.
After debugging this, it seems that if there are many digits after the decimal to plot "render_to_file" command hangs forever.

Code snippet
"""
datetimeline = pygal.DateTimeLine()
data_points = {'key_1': [(datetime.datetime(2019, 11, 4, 0, 0), 221.03), (datetime.datetime(2019, 11, 1, 0, 0), 221.03)], 'key_2': [(datetime.datetime(2019, 11, 4, 0, 0), 221.03000000000006), (datetime.datetime(2019, 11, 1, 0, 0), 221.0300000000001)]}

for key, value in data_points.items():
datetimeline.add(key, value)

datetimeline.render_to_file("some_file.svg") --> this is where it hangs
"""

Inorder to make my code work, I just rounded up the number to 2 decimals.

Can we have a decent message if there is a restriction on the float values or can we have some timeout, so the code doesn't hang forever?

Contributor guide

Open the contributing guide

Research direction

Reproduce the hang with the provided DateTimeLine data and the render_to_file entry point, comparing the two float-value cases. Trace how render_to_file handles numeric values, then verify that excessive decimal precision no longer hangs and that the resulting behavior is bounded by a clear message or timeout.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.