Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions folium/plugins/heat_map.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
import warnings

import numpy as np
Expand Down Expand Up @@ -78,11 +79,28 @@ def __init__(
super().__init__(name=name, overlay=overlay, control=control, show=show)
self._name = "HeatMap"
data = if_pandas_df_convert_to_numpy(data)
weights = {}

def convert_weight(value):
weight = float(value)
# Keep negative zero distinct from positive zero in the output.
if weight == 0.0 and math.copysign(1.0, weight) < 0:
return weight
if len(weights) < 256:
return weights.setdefault(weight, weight)
return weights.get(weight, weight)

self.data = [
[*validate_location(line[:2]), *[float(w) for w in line[2:]]]
validate_location(line[:2]) + [convert_weight(w) for w in line[2:]]
for line in data # noqa: E999
]
if np.any(np.isnan(self.data)):
width = len(self.data[0]) if self.data else 0
if any(len(row) != width for row in self.data):
# Let NumPy report the original error for ragged input.
has_nan = np.any(np.isnan(self.data))
else:
has_nan = any(math.isnan(value) for row in self.data for value in row)
if has_nan:
raise ValueError("data may not contain NaNs.")
if kwargs.pop("max_val", None):
warnings.warn(
Expand Down