Commit 51da98f
authored
Fix HeatMap crash on integer numpy weight arrays (#2244)
HeatMap's docstring documents numpy arrays of shape (n, 2) or (n, 3) as valid
input, but an all-integer array (dtype int64) crashes at render time with
"Object of type int64 is not JSON serializable". validate_location coerces the
lat/lon columns to Python float, while the weight column (line[2:]) was passed
through unchanged. np.float64 is a subclass of float so json.dumps tolerates
float weights, but np.int64 is not a subclass of int, so integer weights fail.
This is common in practice, e.g. HeatMap(df[["lat", "lon", "count"]].values)
where the count column has an integer dtype.
Coerce the weight column to float, mirroring the lat/lon normalization.1 parent 69e7ada commit 51da98f
2 files changed
Lines changed: 42 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
0 commit comments