"No data" for XY graph when using interator with Python 3
- Dominant language
- Python
- Stars
- 2.8k
- Forks
- 419
- PR merge metrics
- No merged PRs in 30d
Description
* Using a `list()` cast avoids the problem.
* not seen with Python 2.7
* plotting two lines, one with iterator and one with list, plots both lines which is confusing
Test case:
#!/usr/bin/env python
# -*- coding: us-ascii -*-
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
# Python 2 or 3
# Bug https://github.com/Kozea/pygal/issues/499
# "No data" for XY graph when using interator with Python 3
import sys
import pygal
print(sys.version)
t_chart = pygal.XY(stroke=True)
t_chart.title = 'interator bug'
#t_chart.x_title = 'Time (seconds)'
#t_chart.y_title = 'Temperature (C)'
t_chart.truncate_legend = 30 # or -1 to disable
# NOTE Python 3.8 needs list cast, iterator does not work
t_chart.add('fails py3 (works py2)', zip(range(1, 10), range(100, 110))) # Py3 shows "No data", unless below is also ran
#t_chart.add('works', list(zip(range(5, 15), range(100, 110)))) # work around for Py3 - NOTE if doing both of these, fails suddenly works and both lines are displayed
filename = 'chart.svg'
t_chart.render_to_file(filename) # py2 and py3
print('check file %s' % filename)
Contributor guide
Research direction
Start with the Python 3 reproducer in the issue, especially pygal.XY.add() with a zip iterator and render_to_file(). Compare the iterator behavior with the list() workaround and confirm the expected result is that the XY graph displays its data without requiring callers to materialize the iterator.
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