Skip to content

Commit 766ce95

Browse files
committed
run ruff
1 parent 2ecbeb1 commit 766ce95

9 files changed

Lines changed: 56 additions & 97 deletions

File tree

folium/features.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,7 @@ def process_data(self, data: Any) -> dict:
707707
return json.loads(json.dumps(data.__geo_interface__))
708708
else:
709709
raise ValueError(
710-
"Cannot render objects with any missing geometries"
711-
": {!r}".format(data)
710+
"Cannot render objects with any missing geometries" f": {data!r}"
712711
)
713712

714713
def get_geojson_from_web(self, url: str) -> dict:
@@ -744,8 +743,8 @@ def _validate_function(self, func: Callable, name: str) -> None:
744743
test_feature = self.data["features"][0]
745744
if not callable(func) or not isinstance(func(test_feature), dict):
746745
raise ValueError(
747-
"{} should be a function that accepts items from "
748-
"data['features'] and returns a dictionary.".format(name)
746+
f"{name} should be a function that accepts items from "
747+
"data['features'] and returns a dictionary."
749748
)
750749

751750
def find_identifier(self) -> str:
@@ -1146,16 +1145,14 @@ def render(self, **kwargs) -> None:
11461145
)
11471146
else:
11481147
raise TypeError(
1149-
"You cannot add a {} to anything other than a "
1150-
"GeoJson or TopoJson object.".format(self._name)
1148+
f"You cannot add a {self._name} to anything other than a "
1149+
"GeoJson or TopoJson object."
11511150
)
11521151
keys = tuple(x for x in keys if x not in ("style", "highlight"))
11531152
for value in self.fields:
11541153
assert (
11551154
value in keys
1156-
), "The field {} is not available in the data. Choose from: {}.".format(
1157-
value, keys
1158-
)
1155+
), f"The field {value} is not available in the data. Choose from: {keys}."
11591156
figure.header.add_child(
11601157
Element(
11611158
Template(

folium/map.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,7 @@ def __init__(
295295
self._name = "Icon"
296296
if color not in self.color_options:
297297
warnings.warn(
298-
"color argument of Icon should be one of: {}.".format(
299-
self.color_options
300-
),
298+
f"color argument of Icon should be one of: {self.color_options}.",
301299
stacklevel=2,
302300
)
303301
self.options = parse_options(
@@ -391,9 +389,7 @@ def _get_self_bounds(self) -> List[List[float]]:
391389
def render(self) -> None:
392390
if self.location is None:
393391
raise ValueError(
394-
"{} location must be assigned when added directly to map.".format(
395-
self._name
396-
)
392+
f"{self._name} location must be assigned when added directly to map."
397393
)
398394
super().render()
399395

@@ -574,9 +570,7 @@ def parse_options(
574570
)
575571
assert isinstance(
576572
kwargs[key], self.valid_options[key]
577-
), "The option {} must be one of the following types: {}.".format(
578-
key, self.valid_options[key]
579-
)
573+
), f"The option {key} must be one of the following types: {self.valid_options[key]}."
580574
return kwargs
581575

582576

folium/plugins/dual_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def __init__(self, location=None, layout="horizontal", **kwargs):
6060
assert key not in kwargs, f"Argument {key} cannot be used with DualMap."
6161
if layout not in ("horizontal", "vertical"):
6262
raise ValueError(
63-
"Undefined option for argument `layout`: {}. "
64-
"Use either 'horizontal' or 'vertical'.".format(layout)
63+
f"Undefined option for argument `layout`: {layout}. "
64+
"Use either 'horizontal' or 'vertical'."
6565
)
6666
width = "50%" if layout == "horizontal" else "100%"
6767
height = "100%" if layout == "horizontal" else "50%"

folium/plugins/search.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __init__(
107107
position="topleft",
108108
placeholder="Search",
109109
collapsed=False,
110-
**kwargs
110+
**kwargs,
111111
):
112112
super().__init__()
113113
assert isinstance(layer, (GeoJson, MarkerCluster, FeatureGroup, TopoJson)), (
@@ -127,9 +127,7 @@ def __init__(
127127
def test_params(self, keys):
128128
if keys is not None and self.search_label is not None:
129129
assert self.search_label in keys, (
130-
"The label '{}' was not "
131-
"available in {}"
132-
"".format(self.search_label, keys)
130+
f"The label '{self.search_label}' was not " f"available in {keys}" ""
133131
)
134132
assert isinstance(
135133
self._parent, Map

folium/plugins/time_slider_choropleth.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ def __init__(
194194
self.styledict = styledict
195195
assert (
196196
-len(timestamps) <= init_timestamp < len(timestamps)
197-
), "init_timestamp must be in the range [-{}, {}) but got {}".format(
198-
len(timestamps), len(timestamps), init_timestamp
199-
)
197+
), f"init_timestamp must be in the range [-{len(timestamps)}, {len(timestamps)}) but got {init_timestamp}"
200198
if init_timestamp < 0:
201199
init_timestamp = len(timestamps) + init_timestamp
202200
self.init_timestamp = init_timestamp

folium/utilities.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,27 @@ def validate_location(location: Sequence[float]) -> List[float]:
7575
raise TypeError(
7676
"Location should be a sized variable, "
7777
"for example a list or a tuple, instead got "
78-
"{!r} of type {}.".format(location, type(location))
78+
f"{location!r} of type {type(location)}."
7979
)
8080
if len(location) != 2:
8181
raise ValueError(
8282
"Expected two (lat, lon) values for location, "
83-
"instead got: {!r}.".format(location)
83+
f"instead got: {location!r}."
8484
)
8585
try:
8686
coords = (location[0], location[1])
8787
except (TypeError, KeyError):
8888
raise TypeError(
8989
"Location should support indexing, like a list or "
90-
"a tuple does, instead got {!r} of type {}.".format(
91-
location, type(location)
92-
)
90+
f"a tuple does, instead got {location!r} of type {type(location)}."
9391
)
9492
for coord in coords:
9593
try:
9694
float(coord)
9795
except (TypeError, ValueError):
9896
raise ValueError(
9997
"Location should consist of two numerical values, "
100-
"but {!r} of type {} is not convertible to float.".format(
101-
coord, type(coord)
102-
)
98+
f"but {coord!r} of type {type(coord)} is not convertible to float."
10399
)
104100
if math.isnan(float(coord)):
105101
raise ValueError("Location values cannot contain NaNs.")
@@ -113,7 +109,7 @@ def _validate_locations_basics(locations: TypeMultiLine) -> None:
113109
except TypeError:
114110
raise TypeError(
115111
"Locations should be an iterable with coordinate pairs,"
116-
" but instead got {!r}.".format(locations)
112+
f" but instead got {locations!r}."
117113
)
118114
try:
119115
next(iter(locations))

tests/plugins/test_polyline_offset.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def test_polylineoffset(offset):
4444
assert script in out
4545

4646
# We verify that the script part is correct.
47-
expected_rendered = """
48-
var {name} = L.polyline(
47+
expected_rendered = f"""
48+
var {polylineoffset.get_name()} = L.polyline(
4949
{locations},
5050
{{
5151
"bubblingMouseEvents": true,
@@ -66,13 +66,8 @@ def test_polylineoffset(offset):
6666
"weight": 3
6767
}}
6868
)
69-
.addTo({map});
70-
""".format(
71-
locations=locations,
72-
name=polylineoffset.get_name(),
73-
offset=offset,
74-
map=m.get_name(),
75-
)
69+
.addTo({m.get_name()});
70+
"""
7671

7772
rendered = polylineoffset._template.module.script(polylineoffset)
7873
assert normalize(expected_rendered) == normalize(rendered)
@@ -94,8 +89,8 @@ def test_polylineoffset_without_offset():
9489
assert script in out
9590

9691
# We verify that the script part is correct.
97-
expected_rendered = """
98-
var {name} = L.polyline(
92+
expected_rendered = f"""
93+
var {polylineoffset.get_name()} = L.polyline(
9994
{locations},
10095
{{
10196
"bubblingMouseEvents": true,
@@ -116,10 +111,8 @@ def test_polylineoffset_without_offset():
116111
"weight": 3
117112
}}
118113
)
119-
.addTo({map});
120-
""".format(
121-
locations=locations, name=polylineoffset.get_name(), map=m.get_name()
122-
)
114+
.addTo({m.get_name()});
115+
"""
123116

124117
rendered = polylineoffset._template.module.script(polylineoffset)
125118
assert normalize(expected_rendered) == normalize(rendered)

tests/test_map.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,11 @@ def test_custom_pane_show():
190190
m = Map()
191191
pane = CustomPane("test-name", z_index=625, pointer_events=False).add_to(m)
192192
rendered = pane._template.module.script(this=pane, kwargs={})
193-
expected = """
194-
var {pane_name} = {map_name}.createPane("test-name");
195-
{pane_name}.style.zIndex = 625;
196-
{pane_name}.style.pointerEvents = 'none';
197-
""".format(
198-
pane_name=pane.get_name(), map_name=m.get_name()
199-
)
193+
expected = f"""
194+
var {pane.get_name()} = {m.get_name()}.createPane("test-name");
195+
{pane.get_name()}.style.zIndex = 625;
196+
{pane.get_name()}.style.pointerEvents = 'none';
197+
"""
200198
assert normalize(rendered) == normalize(expected)
201199

202200

tests/test_vector_layers.py

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def test_circle():
5454
}
5555

5656
m._repr_html_()
57-
expected_rendered = """
58-
var {name} = L.circle(
57+
expected_rendered = f"""
58+
var {circle.get_name()} = L.circle(
5959
{location},
6060
{{
6161
"bubblingMouseEvents": true,
@@ -74,10 +74,8 @@ def test_circle():
7474
"weight": 2
7575
}}
7676
)
77-
.addTo({map});
78-
""".format(
79-
name=circle.get_name(), location=location, radius=radius, map=m.get_name()
80-
) # noqa
77+
.addTo({m.get_name()});
78+
""" # noqa
8179

8280
rendered = circle._template.module.script(circle)
8381
assert normalize(rendered) == normalize(expected_rendered)
@@ -124,8 +122,8 @@ def test_circle_marker():
124122

125123
m._repr_html_()
126124
expected_bounds = [location, location]
127-
expected_rendered = """
128-
var {name} = L.circleMarker(
125+
expected_rendered = f"""
126+
var {circle_marker.get_name()} = L.circleMarker(
129127
{location},
130128
{{
131129
"bubblingMouseEvents": true,
@@ -144,13 +142,8 @@ def test_circle_marker():
144142
"weight": 2
145143
}}
146144
)
147-
.addTo({map});
148-
""".format(
149-
name=circle_marker.get_name(),
150-
location=location,
151-
radius=radius,
152-
map=m.get_name(),
153-
) # noqa
145+
.addTo({m.get_name()});
146+
""" # noqa
154147

155148
rendered = circle_marker._template.module.script(circle_marker)
156149
assert normalize(rendered) == normalize(expected_rendered)
@@ -194,8 +187,8 @@ def test_rectangle():
194187
}
195188

196189
m._repr_html_()
197-
expected_rendered = """
198-
var {name} = L.rectangle(
190+
expected_rendered = f"""
191+
var {rectangle.get_name()} = L.rectangle(
199192
{location},
200193
{{
201194
"bubblingMouseEvents": true,
@@ -215,10 +208,8 @@ def test_rectangle():
215208
"weight": 2
216209
}}
217210
)
218-
.addTo({map});
219-
""".format(
220-
name=rectangle.get_name(), location=location, map=m.get_name()
221-
)
211+
.addTo({m.get_name()});
212+
"""
222213

223214
rendered = rectangle._template.module.script(rectangle)
224215
assert normalize(rendered) == normalize(expected_rendered)
@@ -261,8 +252,8 @@ def test_polygon_marker():
261252
}
262253

263254
m._repr_html_()
264-
expected_rendered = """
265-
var {name} = L.polygon(
255+
expected_rendered = f"""
256+
var {polygon.get_name()} = L.polygon(
266257
{locations},
267258
{{
268259
"bubblingMouseEvents": true,
@@ -282,10 +273,8 @@ def test_polygon_marker():
282273
"weight": 3
283274
}}
284275
)
285-
.addTo({map});
286-
""".format(
287-
locations=locations, name=polygon.get_name(), map=m.get_name()
288-
)
276+
.addTo({m.get_name()});
277+
"""
289278

290279
rendered = polygon._template.module.script(polygon)
291280
assert normalize(rendered) == normalize(expected_rendered)
@@ -319,8 +308,8 @@ def test_polyline():
319308
}
320309

321310
m._repr_html_()
322-
expected_rendered = """
323-
var {name} = L.polyline(
311+
expected_rendered = f"""
312+
var {polyline.get_name()} = L.polyline(
324313
{locations},
325314
{{
326315
"bubblingMouseEvents": true,
@@ -340,10 +329,8 @@ def test_polyline():
340329
"weight": 3
341330
}}
342331
)
343-
.addTo({map});
344-
""".format(
345-
locations=locations, name=polyline.get_name(), map=m.get_name()
346-
)
332+
.addTo({m.get_name()});
333+
"""
347334

348335
rendered = polyline._template.module.script(polyline)
349336
assert normalize(rendered) == normalize(expected_rendered)
@@ -382,8 +369,8 @@ def test_mulyipolyline():
382369
}
383370

384371
m._repr_html_()
385-
expected_rendered = """
386-
var {name} = L.polyline(
372+
expected_rendered = f"""
373+
var {multipolyline.get_name()} = L.polyline(
387374
{locations},
388375
{{
389376
"bubblingMouseEvents": true,
@@ -403,10 +390,8 @@ def test_mulyipolyline():
403390
"weight": 3
404391
}}
405392
)
406-
.addTo({map});
407-
""".format(
408-
locations=locations, name=multipolyline.get_name(), map=m.get_name()
409-
)
393+
.addTo({m.get_name()});
394+
"""
410395

411396
rendered = multipolyline._template.module.script(multipolyline)
412397
assert normalize(rendered) == normalize(expected_rendered)

0 commit comments

Comments
 (0)