Repository navigation
Accept iterators for ColorLine colors - #2397
Open
shashank11yadav wants to merge 1 commit into
Open
shashank11yadav wants to merge 1 commit into
shashank11yadav wants to merge 1 commit into
Conversation
ColorLine documents colors as an iterable of floats, but a generator was consumed by min() before max() and the segment zip could read it. Convert colors to a list once, up front, so all three reads see the same values.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2396
ColorLinedocumentscolorsas an iterable of floats, but a generator or other one-pass iterator fails whencolormapisNoneor a list or tuple. The constructor raisesValueError: max() arg is an empty sequence.min(colors)consumes the iterator, somax(colors)and the segmentzipsee nothing.The fix converts
colorsto a list once, right aftervalidate_locations(positions)inColorLine.__init__(folium/features.py).validate_locationsalready does the same forpositions. TheLinearColormapandStepColormappaths readcolorsonly once, so they are unchanged.The new test
test_color_line_colors_generatorintests/test_features.pyis parametrized overcolormap=Noneand a list colormap. It builds the line from a generator and from a list, and checks that the segments are equal and not empty.How it was tested:
ValueError: max() arg is an empty sequence.tests/test_features.pypasses: 50 passed.foliumpackage: no issues in 51 source files.I did not run
pre-commit run --all-files, because it needs network access to fetch its hook environments. The ruff and black checks above were run. The other pre-commit hooks (blackdoc, codespell, pre-commit-hooks) were not run.