Skip to content

Fix HeatMapWithTime bounds for time-indexed data - #2314

Open
Enesuygurs wants to merge 1 commit into
python-visualization:mainfrom
Enesuygurs:fix/heatmapwithtime-bounds
Open

Enesuygurs wants to merge 1 commit into
python-visualization:mainfrom
Enesuygurs:fix/heatmapwithtime-bounds

Conversation

@Enesuygurs

Copy link
Copy Markdown

HeatMapWithTime._get_self_bounds() looped over self.data as if it were a flat list of points. But data is a list of time steps, and each step holds a list of [lat, lng(, weight)] points. So point[0] and point[1] were whole points, not coordinates.

As a result:

  • get_bounds() returned nested lists such as [[[48.0, 3.0, 0.5], [51.0, 5.0]], ...] instead of [[48.0, 3.0], [52.0, 6.0]].
  • With any other layer on the map, Map.get_bounds() raised TypeError: '<' not supported between instances of 'list' and 'float'.
  • An empty time step raised IndexError.

This breaks the common m.fit_bounds(m.get_bounds()) pattern for maps with a HeatMapWithTime.

import folium
from folium.plugins import HeatMapWithTime

m = folium.Map()
folium.Marker([50, 4]).add_to(m)
HeatMapWithTime([[[48.0, 3.0], [52.0, 6.0]]]).add_to(m)
m.get_bounds()  # TypeError before this change

The fix iterates over the points in every time step. The new test covers weighted points, an empty time step and a map with another layer. It fails without the change and passes with it.

This branch has not been deployed

No deployments
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