Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and fix pre-commits #1797

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
files: requirements-dev.txt

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.277
rev: v0.0.287
hooks:
- id: ruff

Expand Down
15 changes: 6 additions & 9 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ def process_data(self, data: Any) -> dict:
return json.loads(json.dumps(data.__geo_interface__))
else:
raise ValueError(
"Cannot render objects with any missing geometries"
": {!r}".format(data)
"Cannot render objects with any missing geometries" f": {data!r}"
)

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

def find_identifier(self) -> str:
Expand Down Expand Up @@ -1146,16 +1145,14 @@ def render(self, **kwargs) -> None:
)
else:
raise TypeError(
"You cannot add a {} to anything other than a "
"GeoJson or TopoJson object.".format(self._name)
f"You cannot add a {self._name} to anything other than a "
"GeoJson or TopoJson object."
)
keys = tuple(x for x in keys if x not in ("style", "highlight"))
for value in self.fields:
assert (
value in keys
), "The field {} is not available in the data. Choose from: {}.".format(
value, keys
)
), f"The field {value} is not available in the data. Choose from: {keys}."
figure.header.add_child(
Element(
Template(
Expand Down
12 changes: 3 additions & 9 deletions folium/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ def __init__(
self._name = "Icon"
if color not in self.color_options:
warnings.warn(
"color argument of Icon should be one of: {}.".format(
self.color_options
),
f"color argument of Icon should be one of: {self.color_options}.",
stacklevel=2,
)
self.options = parse_options(
Expand Down Expand Up @@ -391,9 +389,7 @@ def _get_self_bounds(self) -> List[List[float]]:
def render(self) -> None:
if self.location is None:
raise ValueError(
"{} location must be assigned when added directly to map.".format(
self._name
)
f"{self._name} location must be assigned when added directly to map."
)
super().render()

Expand Down Expand Up @@ -574,9 +570,7 @@ def parse_options(
)
assert isinstance(
kwargs[key], self.valid_options[key]
), "The option {} must be one of the following types: {}.".format(
key, self.valid_options[key]
)
), f"The option {key} must be one of the following types: {self.valid_options[key]}."
return kwargs


Expand Down
4 changes: 2 additions & 2 deletions folium/plugins/dual_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def __init__(self, location=None, layout="horizontal", **kwargs):
assert key not in kwargs, f"Argument {key} cannot be used with DualMap."
if layout not in ("horizontal", "vertical"):
raise ValueError(
"Undefined option for argument `layout`: {}. "
"Use either 'horizontal' or 'vertical'.".format(layout)
f"Undefined option for argument `layout`: {layout}. "
"Use either 'horizontal' or 'vertical'."
)
width = "50%" if layout == "horizontal" else "100%"
height = "100%" if layout == "horizontal" else "50%"
Expand Down
6 changes: 2 additions & 4 deletions folium/plugins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(
position="topleft",
placeholder="Search",
collapsed=False,
**kwargs
**kwargs,
):
super().__init__()
assert isinstance(layer, (GeoJson, MarkerCluster, FeatureGroup, TopoJson)), (
Expand All @@ -127,9 +127,7 @@ def __init__(
def test_params(self, keys):
if keys is not None and self.search_label is not None:
assert self.search_label in keys, (
"The label '{}' was not "
"available in {}"
"".format(self.search_label, keys)
f"The label '{self.search_label}' was not " f"available in {keys}" ""
)
assert isinstance(
self._parent, Map
Expand Down
4 changes: 1 addition & 3 deletions folium/plugins/time_slider_choropleth.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ def __init__(
self.styledict = styledict
assert (
-len(timestamps) <= init_timestamp < len(timestamps)
), "init_timestamp must be in the range [-{}, {}) but got {}".format(
len(timestamps), len(timestamps), init_timestamp
)
), f"init_timestamp must be in the range [-{len(timestamps)}, {len(timestamps)}) but got {init_timestamp}"
if init_timestamp < 0:
init_timestamp = len(timestamps) + init_timestamp
self.init_timestamp = init_timestamp
14 changes: 5 additions & 9 deletions folium/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,27 @@ def validate_location(location: Sequence[float]) -> List[float]:
raise TypeError(
"Location should be a sized variable, "
"for example a list or a tuple, instead got "
"{!r} of type {}.".format(location, type(location))
f"{location!r} of type {type(location)}."
)
if len(location) != 2:
raise ValueError(
"Expected two (lat, lon) values for location, "
"instead got: {!r}.".format(location)
f"instead got: {location!r}."
)
try:
coords = (location[0], location[1])
except (TypeError, KeyError):
raise TypeError(
"Location should support indexing, like a list or "
"a tuple does, instead got {!r} of type {}.".format(
location, type(location)
)
f"a tuple does, instead got {location!r} of type {type(location)}."
)
for coord in coords:
try:
float(coord)
except (TypeError, ValueError):
raise ValueError(
"Location should consist of two numerical values, "
"but {!r} of type {} is not convertible to float.".format(
coord, type(coord)
)
f"but {coord!r} of type {type(coord)} is not convertible to float."
)
if math.isnan(float(coord)):
raise ValueError("Location values cannot contain NaNs.")
Expand All @@ -113,7 +109,7 @@ def _validate_locations_basics(locations: TypeMultiLine) -> None:
except TypeError:
raise TypeError(
"Locations should be an iterable with coordinate pairs,"
" but instead got {!r}.".format(locations)
f" but instead got {locations!r}."
)
try:
next(iter(locations))
Expand Down
23 changes: 8 additions & 15 deletions tests/plugins/test_polyline_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test_polylineoffset(offset):
assert script in out

# We verify that the script part is correct.
expected_rendered = """
var {name} = L.polyline(
expected_rendered = f"""
var {polylineoffset.get_name()} = L.polyline(
{locations},
{{
"bubblingMouseEvents": true,
Expand All @@ -66,13 +66,8 @@ def test_polylineoffset(offset):
"weight": 3
}}
)
.addTo({map});
""".format(
locations=locations,
name=polylineoffset.get_name(),
offset=offset,
map=m.get_name(),
)
.addTo({m.get_name()});
"""

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

# We verify that the script part is correct.
expected_rendered = """
var {name} = L.polyline(
expected_rendered = f"""
var {polylineoffset.get_name()} = L.polyline(
{locations},
{{
"bubblingMouseEvents": true,
Expand All @@ -116,10 +111,8 @@ def test_polylineoffset_without_offset():
"weight": 3
}}
)
.addTo({map});
""".format(
locations=locations, name=polylineoffset.get_name(), map=m.get_name()
)
.addTo({m.get_name()});
"""

rendered = polylineoffset._template.module.script(polylineoffset)
assert normalize(expected_rendered) == normalize(rendered)
12 changes: 5 additions & 7 deletions tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,11 @@ def test_custom_pane_show():
m = Map()
pane = CustomPane("test-name", z_index=625, pointer_events=False).add_to(m)
rendered = pane._template.module.script(this=pane, kwargs={})
expected = """
var {pane_name} = {map_name}.createPane("test-name");
{pane_name}.style.zIndex = 625;
{pane_name}.style.pointerEvents = 'none';
""".format(
pane_name=pane.get_name(), map_name=m.get_name()
)
expected = f"""
var {pane.get_name()} = {m.get_name()}.createPane("test-name");
{pane.get_name()}.style.zIndex = 625;
{pane.get_name()}.style.pointerEvents = 'none';
"""
assert normalize(rendered) == normalize(expected)


Expand Down
63 changes: 24 additions & 39 deletions tests/test_vector_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def test_circle():
}

m._repr_html_()
expected_rendered = """
var {name} = L.circle(
expected_rendered = f"""
var {circle.get_name()} = L.circle(
{location},
{{
"bubblingMouseEvents": true,
Expand All @@ -74,10 +74,8 @@ def test_circle():
"weight": 2
}}
)
.addTo({map});
""".format(
name=circle.get_name(), location=location, radius=radius, map=m.get_name()
) # noqa
.addTo({m.get_name()});
""" # noqa

rendered = circle._template.module.script(circle)
assert normalize(rendered) == normalize(expected_rendered)
Expand Down Expand Up @@ -124,8 +122,8 @@ def test_circle_marker():

m._repr_html_()
expected_bounds = [location, location]
expected_rendered = """
var {name} = L.circleMarker(
expected_rendered = f"""
var {circle_marker.get_name()} = L.circleMarker(
{location},
{{
"bubblingMouseEvents": true,
Expand All @@ -144,13 +142,8 @@ def test_circle_marker():
"weight": 2
}}
)
.addTo({map});
""".format(
name=circle_marker.get_name(),
location=location,
radius=radius,
map=m.get_name(),
) # noqa
.addTo({m.get_name()});
""" # noqa

rendered = circle_marker._template.module.script(circle_marker)
assert normalize(rendered) == normalize(expected_rendered)
Expand Down Expand Up @@ -194,8 +187,8 @@ def test_rectangle():
}

m._repr_html_()
expected_rendered = """
var {name} = L.rectangle(
expected_rendered = f"""
var {rectangle.get_name()} = L.rectangle(
{location},
{{
"bubblingMouseEvents": true,
Expand All @@ -215,10 +208,8 @@ def test_rectangle():
"weight": 2
}}
)
.addTo({map});
""".format(
name=rectangle.get_name(), location=location, map=m.get_name()
)
.addTo({m.get_name()});
"""

rendered = rectangle._template.module.script(rectangle)
assert normalize(rendered) == normalize(expected_rendered)
Expand Down Expand Up @@ -261,8 +252,8 @@ def test_polygon_marker():
}

m._repr_html_()
expected_rendered = """
var {name} = L.polygon(
expected_rendered = f"""
var {polygon.get_name()} = L.polygon(
{locations},
{{
"bubblingMouseEvents": true,
Expand All @@ -282,10 +273,8 @@ def test_polygon_marker():
"weight": 3
}}
)
.addTo({map});
""".format(
locations=locations, name=polygon.get_name(), map=m.get_name()
)
.addTo({m.get_name()});
"""

rendered = polygon._template.module.script(polygon)
assert normalize(rendered) == normalize(expected_rendered)
Expand Down Expand Up @@ -319,8 +308,8 @@ def test_polyline():
}

m._repr_html_()
expected_rendered = """
var {name} = L.polyline(
expected_rendered = f"""
var {polyline.get_name()} = L.polyline(
{locations},
{{
"bubblingMouseEvents": true,
Expand All @@ -340,10 +329,8 @@ def test_polyline():
"weight": 3
}}
)
.addTo({map});
""".format(
locations=locations, name=polyline.get_name(), map=m.get_name()
)
.addTo({m.get_name()});
"""

rendered = polyline._template.module.script(polyline)
assert normalize(rendered) == normalize(expected_rendered)
Expand Down Expand Up @@ -382,8 +369,8 @@ def test_mulyipolyline():
}

m._repr_html_()
expected_rendered = """
var {name} = L.polyline(
expected_rendered = f"""
var {multipolyline.get_name()} = L.polyline(
{locations},
{{
"bubblingMouseEvents": true,
Expand All @@ -403,10 +390,8 @@ def test_mulyipolyline():
"weight": 3
}}
)
.addTo({map});
""".format(
locations=locations, name=multipolyline.get_name(), map=m.get_name()
)
.addTo({m.get_name()});
"""

rendered = multipolyline._template.module.script(multipolyline)
assert normalize(rendered) == normalize(expected_rendered)
Expand Down