From 3e3ce8833df767cec361085e0767f478168c9ba7 Mon Sep 17 00:00:00 2001 From: Hans Then Date: Sun, 31 May 2026 22:20:03 +0200 Subject: [PATCH 1/4] Fix formatting --- folium/elements.py | 12 ++++++++---- folium/plugins/draw.py | 8 ++++++-- folium/plugins/timeline.py | 6 ++++-- folium/plugins/webgl_earth.py | 6 ++++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/folium/elements.py b/folium/elements.py index 753a55ad06..88637fb1b6 100644 --- a/folium/elements.py +++ b/folium/elements.py @@ -101,18 +101,22 @@ class EventHandler(MacroElement): >>> >>> g = folium.GeoJson(geo_json_data).add_to(m) >>> - >>> highlight = JsCode(""" + >>> highlight = JsCode( + ... """ ... function highlight(e) { ... e.target.original_color = e.layer.options.color; ... e.target.setStyle({ color: "green" }); ... } - ... """) + ... """ + ... ) >>> - >>> reset = JsCode(""" + >>> reset = JsCode( + ... """ ... function reset(e) { ... e.target.setStyle({ color: e.target.original_color }); ... } - ... """) + ... """ + ... ) >>> >>> g.add_child(EventHandler("mouseover", highlight)) >>> g.add_child(EventHandler("mouseout", reset)) diff --git a/folium/plugins/draw.py b/folium/plugins/draw.py index 7d54f1805d..5b524a51a7 100644 --- a/folium/plugins/draw.py +++ b/folium/plugins/draw.py @@ -42,11 +42,15 @@ class Draw(JSCSSMixin, MacroElement): ... position="topleft", ... draw_options={"polyline": {"allowIntersection": False}}, ... edit_options={"poly": {"allowIntersection": False}}, - ... on={"click": JsCode(""" + ... on={ + ... "click": JsCode( + ... """ ... function(event) { ... alert(JSON.stringify(this.toGeoJSON())); ... } - ... """)}, + ... """ + ... ) + ... }, ... ).add_to(m) For more info please check diff --git a/folium/plugins/timeline.py b/folium/plugins/timeline.py index 4d701d3a85..e0bc66f10b 100644 --- a/folium/plugins/timeline.py +++ b/folium/plugins/timeline.py @@ -53,7 +53,8 @@ class Timeline(GeoJson): >>> timeline = Timeline( ... data, - ... get_interval=JsCode(''' + ... get_interval=JsCode( + ... ''' ... function (quake) { ... // earthquake data only has a time, so we\'ll use that as a "start" ... // and the "end" will be that + some value based on magnitude @@ -64,7 +65,8 @@ class Timeline(GeoJson): ... end: quake.properties.time + quake.properties.mag * 1800000, ... }; ... }; - ... '''), + ... ''' + ... ), ... ).add_to(m) >>> TimelineSlider( ... auto_play=False, diff --git a/folium/plugins/webgl_earth.py b/folium/plugins/webgl_earth.py index 8ba53599e0..3fb0fb10b7 100644 --- a/folium/plugins/webgl_earth.py +++ b/folium/plugins/webgl_earth.py @@ -279,14 +279,16 @@ class WebGLEarthRealtime(JSCSSMixin, MacroElement): >>> iss = WebGLEarthRealtime( ... source_url="https://api.wheretheiss.at/v1/satellites/25544", ... interval=3000, - ... on_update=JsCode(''' + ... on_update=JsCode( + ... ''' ... function(data, earth) { ... if (window._issMarker) window._issMarker.removeFrom(earth); ... window._issMarker = WE.marker( ... [data.latitude, data.longitude] ... ).addTo(earth); ... } - ... '''), + ... ''' + ... ), ... ) >>> iss.add_to(globe) """ From 3b71c68f21f13b1ff74df47d75e64029f0548461 Mon Sep 17 00:00:00 2001 From: Hans Then Date: Sun, 31 May 2026 22:31:19 +0200 Subject: [PATCH 2/4] Fix issue with Chroropleth docstring --- folium/features.py | 227 +++++++++++++++++++++++---------------------- 1 file changed, 114 insertions(+), 113 deletions(-) diff --git a/folium/features.py b/folium/features.py index 12d663cb05..a3b86db983 100644 --- a/folium/features.py +++ b/folium/features.py @@ -1382,120 +1382,121 @@ def __init__( class Choropleth(FeatureGroup): - """Apply a GeoJSON overlay to the map. - - Plot a GeoJSON overlay on the base map. There is no requirement - to bind data (passing just a GeoJSON plots a single-color overlay), - but there is a data binding option to map your columnar data to - different feature objects with a color scale. - - If data is passed as a Pandas DataFrame, the "columns" and "key-on" - keywords must be included, the first to indicate which DataFrame - columns to use, the second to indicate the layer in the GeoJSON - on which to key the data. The 'columns' keyword does not need to be - passed for a Pandas series. - - Colors are generated from color brewer (https://colorbrewer2.org/) - sequential palettes. By default, linear binning is used between - the min and the max of the values. Custom binning can be achieved - with the `bins` parameter. - - TopoJSONs can be passed as "geo_data", but the "topojson" keyword must - also be passed with the reference to the topojson objects to convert. - See the topojson.feature method in the TopoJSON API reference: - https://github.com/topojson/topojson/wiki/API-Reference - - - Parameters - ---------- - geo_data: string/object - URL, file path, or data (json, dict, geopandas, etc) to your GeoJSON - geometries - data: Pandas DataFrame or Series, default None - Data to bind to the GeoJSON. - columns: tuple with two values, default None - If the data is a Pandas DataFrame, the columns of data to be bound. - Must pass column 1 as the key, and column 2 the values. - key_on: string, default None - Variable in the `geo_data` GeoJSON file to bind the data to. Must - start with 'feature' and be in JavaScript objection notation. - Ex: 'feature.id' or 'feature.properties.statename'. - bins: int or sequence of scalars or str, default 6 - If `bins` is an int, it defines the number of equal-width - bins between the min and the max of the values. - If `bins` is a sequence, it directly defines the bin edges. - For more information on this parameter, have a look at - numpy.histogram function. + """ + Apply a GeoJSON overlay to the map. + + Plot a GeoJSON overlay on the base map. There is no requirement + to bind data (passing just a GeoJSON plots a single-color overlay), + but there is a data binding option to map your columnar data to + different feature objects with a color scale. + + If data is passed as a Pandas DataFrame, the "columns" and "key-on" + keywords must be included, the first to indicate which DataFrame + columns to use, the second to indicate the layer in the GeoJSON + on which to key the data. The 'columns' keyword does not need to be + passed for a Pandas series. + + Colors are generated from color brewer (https://colorbrewer2.org/) + sequential palettes. By default, linear binning is used between + the min and the max of the values. Custom binning can be achieved + with the `bins` parameter. + + TopoJSONs can be passed as "geo_data", but the "topojson" keyword must + also be passed with the reference to the topojson objects to convert. + See the topojson.feature method in the TopoJSON API reference: + https://github.com/topojson/topojson/wiki/API-Reference + + + Parameters + ---------- + geo_data: string/object + URL, file path, or data (json, dict, geopandas, etc) to your GeoJSON + geometries + data: Pandas DataFrame or Series, default None + Data to bind to the GeoJSON. + columns: tuple with two values, default None + If the data is a Pandas DataFrame, the columns of data to be bound. + Must pass column 1 as the key, and column 2 the values. + key_on: string, default None + Variable in the `geo_data` GeoJSON file to bind the data to. Must + start with 'feature' and be in JavaScript objection notation. + Ex: 'feature.id' or 'feature.properties.statename'. + bins: int or sequence of scalars or str, default 6 + If `bins` is an int, it defines the number of equal-width + bins between the min and the max of the values. + If `bins` is a sequence, it directly defines the bin edges. + For more information on this parameter, have a look at + numpy.histogram function. fill_color: string, optional - Area fill color, defaults to blue. Can pass a hex code, color name, - or if you are binding data, one of the following color brewer palettes: - 'BuGn', 'BuPu', 'GnBu', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'RdPu', - 'YlGn', 'YlGnBu', 'YlOrBr', and 'YlOrRd'. - You can also pass any colormap name supported by branca such as - 'viridis', 'plasma', 'magma', 'Blues' etc. For all available options see: - https://python-visualization.github.io/branca/colormap.html - nan_fill_color: string, default 'black' - Area fill color for nan or missing values. - Can pass a hex code, color name. - fill_opacity: float, default 0.6 - Area fill opacity, range 0-1. - nan_fill_opacity: float, default fill_opacity - Area fill opacity for nan or missing values, range 0-1. - line_color: string, default 'black' - GeoJSON geopath line color. - line_weight: int, default 1 - GeoJSON geopath line weight. - line_opacity: float, default 1 - GeoJSON geopath line opacity, range 0-1. - legend_name: string, default empty string - Title for data legend. - topojson: string, default None - If using a TopoJSON, passing "objects.yourfeature" to the topojson - keyword argument will enable conversion to GeoJSON. - smooth_factor: float, default None - How much to simplify the polyline on each zoom level. More means - better performance and smoother look, and less means more accurate - representation. Leaflet defaults to 1.0. - highlight: boolean, default False - Enable highlight functionality when hovering over a GeoJSON area. - use_jenks: bool, default False - Use jenkspy to calculate bins using "natural breaks" - (Fisher-Jenks algorithm). This is useful when your data is unevenly - distributed. - name : string, optional - The name of the layer, as it will appear in LayerControls - overlay : bool, default True - Adds the layer as an optional overlay (True) or the base layer (False). - control : bool, default True - Whether the Layer will be included in LayerControls. - show: bool, default True - Whether the layer will be shown on opening. - - Returns - ------- - GeoJSON data layer in obj.template_vars - - Examples - -------- - >>> Choropleth(geo_data="us-states.json", line_color="blue", line_weight=3) - >>> Choropleth( - ... geo_data="geo.json", - ... data=df, - ... columns=["Data 1", "Data 2"], - ... key_on="feature.properties.myvalue", - ... fill_color="PuBu", - ... bins=[0, 20, 30, 40, 50, 60], - ... ) - >>> Choropleth(geo_data="countries.json", topojson="objects.countries") - >>> Choropleth( - ... geo_data="geo.json", - ... data=df, - ... columns=["Data 1", "Data 2"], - ... key_on="feature.properties.myvalue", - ... fill_color="PuBu", - ... bins=[0, 20, 30, 40, 50, 60], - ... highlight=True, - ... ) + Area fill color, defaults to blue. Can pass a hex code, color name, + or if you are binding data, one of the following color brewer palettes: + 'BuGn', 'BuPu', 'GnBu', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'RdPu', + 'YlGn', 'YlGnBu', 'YlOrBr', and 'YlOrRd'. + You can also pass any colormap name supported by branca such as + 'viridis', 'plasma', 'magma', 'Blues' etc. For all available options see: + https://python-visualization.github.io/branca/colormap.html + nan_fill_color: string, default 'black' + Area fill color for nan or missing values. + Can pass a hex code, color name. + fill_opacity: float, default 0.6 + Area fill opacity, range 0-1. + nan_fill_opacity: float, default fill_opacity + Area fill opacity for nan or missing values, range 0-1. + line_color: string, default 'black' + GeoJSON geopath line color. + line_weight: int, default 1 + GeoJSON geopath line weight. + line_opacity: float, default 1 + GeoJSON geopath line opacity, range 0-1. + legend_name: string, default empty string + Title for data legend. + topojson: string, default None + If using a TopoJSON, passing "objects.yourfeature" to the topojson + keyword argument will enable conversion to GeoJSON. + smooth_factor: float, default None + How much to simplify the polyline on each zoom level. More means + better performance and smoother look, and less means more accurate + representation. Leaflet defaults to 1.0. + highlight: boolean, default False + Enable highlight functionality when hovering over a GeoJSON area. + use_jenks: bool, default False + Use jenkspy to calculate bins using "natural breaks" + (Fisher-Jenks algorithm). This is useful when your data is unevenly + distributed. + name : string, optional + The name of the layer, as it will appear in LayerControls + overlay : bool, default True + Adds the layer as an optional overlay (True) or the base layer (False). + control : bool, default True + Whether the Layer will be included in LayerControls. + show: bool, default True + Whether the layer will be shown on opening. + + Returns + ------- + GeoJSON data layer in obj.template_vars + + Examples + -------- + >>> Choropleth(geo_data="us-states.json", line_color="blue", line_weight=3) + >>> Choropleth( + ... geo_data="geo.json", + ... data=df, + ... columns=["Data 1", "Data 2"], + ... key_on="feature.properties.myvalue", + ... fill_color="PuBu", + ... bins=[0, 20, 30, 40, 50, 60], + ... ) + >>> Choropleth(geo_data="countries.json", topojson="objects.countries") + >>> Choropleth( + ... geo_data="geo.json", + ... data=df, + ... columns=["Data 1", "Data 2"], + ... key_on="feature.properties.myvalue", + ... fill_color="PuBu", + ... bins=[0, 20, 30, 40, 50, 60], + ... highlight=True, + ... ) """ def __init__( From 4b8180fcb92f5dba6f812085908a157f6e7fa47a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 31 May 2026 20:38:10 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- folium/elements.py | 12 ++++-------- folium/plugins/draw.py | 8 ++------ folium/plugins/timeline.py | 6 ++---- folium/plugins/webgl_earth.py | 6 ++---- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/folium/elements.py b/folium/elements.py index 88637fb1b6..753a55ad06 100644 --- a/folium/elements.py +++ b/folium/elements.py @@ -101,22 +101,18 @@ class EventHandler(MacroElement): >>> >>> g = folium.GeoJson(geo_json_data).add_to(m) >>> - >>> highlight = JsCode( - ... """ + >>> highlight = JsCode(""" ... function highlight(e) { ... e.target.original_color = e.layer.options.color; ... e.target.setStyle({ color: "green" }); ... } - ... """ - ... ) + ... """) >>> - >>> reset = JsCode( - ... """ + >>> reset = JsCode(""" ... function reset(e) { ... e.target.setStyle({ color: e.target.original_color }); ... } - ... """ - ... ) + ... """) >>> >>> g.add_child(EventHandler("mouseover", highlight)) >>> g.add_child(EventHandler("mouseout", reset)) diff --git a/folium/plugins/draw.py b/folium/plugins/draw.py index 5b524a51a7..7d54f1805d 100644 --- a/folium/plugins/draw.py +++ b/folium/plugins/draw.py @@ -42,15 +42,11 @@ class Draw(JSCSSMixin, MacroElement): ... position="topleft", ... draw_options={"polyline": {"allowIntersection": False}}, ... edit_options={"poly": {"allowIntersection": False}}, - ... on={ - ... "click": JsCode( - ... """ + ... on={"click": JsCode(""" ... function(event) { ... alert(JSON.stringify(this.toGeoJSON())); ... } - ... """ - ... ) - ... }, + ... """)}, ... ).add_to(m) For more info please check diff --git a/folium/plugins/timeline.py b/folium/plugins/timeline.py index e0bc66f10b..4d701d3a85 100644 --- a/folium/plugins/timeline.py +++ b/folium/plugins/timeline.py @@ -53,8 +53,7 @@ class Timeline(GeoJson): >>> timeline = Timeline( ... data, - ... get_interval=JsCode( - ... ''' + ... get_interval=JsCode(''' ... function (quake) { ... // earthquake data only has a time, so we\'ll use that as a "start" ... // and the "end" will be that + some value based on magnitude @@ -65,8 +64,7 @@ class Timeline(GeoJson): ... end: quake.properties.time + quake.properties.mag * 1800000, ... }; ... }; - ... ''' - ... ), + ... '''), ... ).add_to(m) >>> TimelineSlider( ... auto_play=False, diff --git a/folium/plugins/webgl_earth.py b/folium/plugins/webgl_earth.py index 3fb0fb10b7..8ba53599e0 100644 --- a/folium/plugins/webgl_earth.py +++ b/folium/plugins/webgl_earth.py @@ -279,16 +279,14 @@ class WebGLEarthRealtime(JSCSSMixin, MacroElement): >>> iss = WebGLEarthRealtime( ... source_url="https://api.wheretheiss.at/v1/satellites/25544", ... interval=3000, - ... on_update=JsCode( - ... ''' + ... on_update=JsCode(''' ... function(data, earth) { ... if (window._issMarker) window._issMarker.removeFrom(earth); ... window._issMarker = WE.marker( ... [data.latitude, data.longitude] ... ).addTo(earth); ... } - ... ''' - ... ), + ... '''), ... ) >>> iss.add_to(globe) """ From 438e3dcfd5051600cdb6cddf1c20265f7403c781 Mon Sep 17 00:00:00 2001 From: Hans Then Date: Sun, 31 May 2026 23:37:44 +0200 Subject: [PATCH 4/4] Try to fix the timeout issues --- docs/user_guide/plugins/WmsTimeDimension.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user_guide/plugins/WmsTimeDimension.md b/docs/user_guide/plugins/WmsTimeDimension.md index 158e6c7958..f21be758b8 100644 --- a/docs/user_guide/plugins/WmsTimeDimension.md +++ b/docs/user_guide/plugins/WmsTimeDimension.md @@ -10,7 +10,7 @@ from owslib.wms import WebMapService url = "https://pae-paha.pacioos.hawaii.edu/thredds/wms/dhw_5km?service=WMS" -web_map_services = WebMapService(url) +web_map_services = WebMapService(url, timeout=100) print("\n".join(web_map_services.contents.keys())) ```