Skip to content

Preserve iterator coordinates during location validation - #2299

Open
greg-oyan wants to merge 2 commits into
python-visualization:mainfrom
greg-oyan:fix/preserve-location-iterators
Open

greg-oyan wants to merge 2 commits into
python-visualization:mainfrom
greg-oyan:fix/preserve-location-iterators

Conversation

@greg-oyan

Copy link
Copy Markdown

Problem

Location validation consumes coordinates from single-pass iterators while checking whether the input is empty and whether it contains multiple lines. This silently changes geometry passed to PolyLine.

For example:

import folium

points = [(0, 5), (1, 6), (2, 7)]
line = folium.PolyLine(iter(points))
print(line.locations)

Before this change, the result is [[2.0, 7.0]]: the first two vertices disappear. Single-point iterators become empty, and nested line iterators also lose vertices.

Changes

Materialize outer iterators before the validation checks and inner line iterators before checking nesting. Lists, arrays, and DataFrames retain their existing validation paths.

Add regressions for list iterators, generator expressions, single-point inputs, empty iterators, and nested line iterators.

Validation

  • Before the fix, the new iterator tests produced 10 failures and 2 passes.
  • python -m pytest tests/test_utilities.py tests/test_vector_layers.py tests/plugins/test_marker_cluster.py -q: 95 passed.
  • ruff check folium/utilities.py tests/test_utilities.py: passed.
  • black --check folium/utilities.py tests/test_utilities.py: passed.
  • git diff --check: passed.

The full non-Selenium suite was attempted but could not collect unrelated tests because Pillow and GeoPandas were not installed. Browser tests were not run.

Prepared with AI assistance.

This branch was successfully deployed

1 active deployment
pypi — cfb0ff7e Deployed Oct 15, 2026 by greg-oyan via packages #1968
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant