You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ColorLine raises ValueError when colors is a generator #2396
folium.ColorLine documents colors as an iterable of float (colors: Iterable[float]). Passing a generator raises ValueError: max() iterable argument is empty when colormap is None, a list or a tuple. min(colors) consumes the generator, so max(colors) sees nothing. A list works. positions had the same problem with iterators and was fixed in #2299.
To Reproduce
importfoliumpos= [[0, 0], [1, 1], [2, 2]]
vals= [0.1, 0.9]
ctl=folium.ColorLine(positions=pos, colors=list(vals))
print("control (list) polylines:", len(ctl._children))
print("EXPECTED: ColorLine accepts iterable of float (generator) like a list")
cl=folium.ColorLine(positions=pos, colors=(cforcinvals))
print("ACTUAL: built with", len(cl._children), "polylines")
folium/features.py:2007-2008 and :2015-2016 call min(colors) then max(colors). The final zip(..., colors) at :2026 reads colors again, so fixing only min/max would still give no segments.
Possible solutions
Convert with colors = list(colors) right after validate_locations, which fixes both places.
I have a fix with a regression test ready and will open a pull request for it right after filing this issue; it will link back here.
Activity