Skip to content

Commit

Permalink
chore: update unittest and improvement typehinting (#835)
Browse files Browse the repository at this point in the history
* chore: update unittest and improvement typehinting

Signed-off-by: slowy07 <[email protected]>

* chore: adding typehinting on heremap and plotlymap

Signed-off-by: slowy07 <[email protected]>

* fix: delete us_states.kml

Signed-off-by: slowy07 <[email protected]>

---------

Signed-off-by: slowy07 <[email protected]>
  • Loading branch information
slowy07 authored Jul 19, 2024
1 parent 767e0e7 commit f45cf5f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
18 changes: 9 additions & 9 deletions leafmap/heremap.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def zoom_to_gdf(self, gdf: GeoDataFrame):
bounds = gdf.total_bounds
self.zoom_to_bounds(bounds)

def add_basemap(self, basemap: Optional[str] = "HYBRID"):
def add_basemap(self, basemap: Optional[str] = "HYBRID") -> None:
"""Adds a basemap to the map.
Args:
Expand Down Expand Up @@ -169,7 +169,7 @@ def add_tile_layer(
attribution: str,
opacity: Optional[float] = 1.0,
**kwargs,
):
) -> None:
"""Adds a TileLayer to the map.
Args:
Expand Down Expand Up @@ -203,7 +203,7 @@ def add_geojson(
info_mode: Optional[str] = "on_hover",
point_style: Optional[Dict] = None,
default_popup: Optional[bool] = False,
):
) -> None:
"""Adds a GeoJSON file to the map.
Args:
Expand Down Expand Up @@ -350,7 +350,7 @@ def add_shp(
info_mode: Optional[str] = "on_hover",
point_style: Optional[Dict] = None,
default_popup: Optional[bool] = False,
):
) -> None:
"""Adds a shapefile to the map.
Args:
Expand Down Expand Up @@ -396,7 +396,7 @@ def add_gdf(
zoom_to_layer: Optional[bool] = True,
point_style: Optional[Dict] = None,
default_popup: Optional[bool] = False,
):
) -> None:
"""Adds a GeoJSON file to the map.
Args:
Expand Down Expand Up @@ -445,7 +445,7 @@ def add_kml(
info_mode: Optional[str] = "on_hover",
point_style: Optional[Dict] = None,
default_popup: Optional[bool] = False,
):
) -> None:
"""Adds a GeoJSON file to the map.
Args:
Expand Down Expand Up @@ -497,7 +497,7 @@ def add_vector(
point_style: Optional[Dict] = None,
default_popup: Optional[bool] = False,
**kwargs,
):
) -> None:
"""Adds any geopandas-supported vector dataset to the map.
Args:
Expand Down Expand Up @@ -572,7 +572,7 @@ def to_html(
width: Optional[str] = "100%",
height: Optional[str] = "880px",
**kwargs,
):
) -> None:
"""Saves the map as an HTML file.
Args:
Expand Down Expand Up @@ -642,7 +642,7 @@ def to_streamlit(
responsive: Optional[bool] = True,
scrolling: Optional[bool] = False,
**kwargs,
):
) -> None:
"""Renders map figure in a Streamlit app.
Args:
Expand Down
50 changes: 25 additions & 25 deletions leafmap/plotlymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
map_max_width: Optional[str] = "98%",
map_refresh: Optional[bool] = False,
**kwargs,
):
) -> None:
"""Initialize the Canvas.
Args:
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(
basemap: Optional[str] = "open-street-map",
height: Optional[int] = 600,
**kwargs,
):
) -> None:
"""Initializes a map. More info at https://plotly.com/python/mapbox-layers/
Args:
Expand Down Expand Up @@ -111,7 +111,7 @@ def show(
map_max_width: Optional[str] = "98%",
refresh: Optional[bool] = False,
**kwargs,
):
) -> None:
"""Shows the map.
Args:
Expand Down Expand Up @@ -145,7 +145,7 @@ def clear_controls(self):
}
self.show(toolbar=False, config=config)

def add_controls(self, controls: List):
def add_controls(self, controls: List) -> None:
"""Adds controls to the map.
Args:
Expand Down Expand Up @@ -175,7 +175,7 @@ def remove_controls(self, controls: List):

self.update_layout(modebar_remove=controls)

def set_center(self, lat: float, lon: float, zoom: Optional[float] = None):
def set_center(self, lat: float, lon: float, zoom: Optional[float] = None) -> None:
"""Sets the center of the map.
Args:
Expand All @@ -190,7 +190,7 @@ def set_center(self, lat: float, lon: float, zoom: Optional[float] = None):
)
)

def add_basemap(self, basemap: Optional[str] = "ROADMAP"):
def add_basemap(self, basemap: Optional[str] = "ROADMAP") -> None:
"""Adds a basemap to the map.
Args:
Expand All @@ -206,7 +206,7 @@ def add_basemap(self, basemap: Optional[str] = "ROADMAP"):
layers = list(self.layout.mapbox.layers) + [basemaps[basemap]]
self.update_layout(mapbox_layers=layers)

def remove_basemap(self, name: str):
def remove_basemap(self, name: str) -> None:
"""Removes a basemap from the map.
Args:
Expand All @@ -216,7 +216,7 @@ def remove_basemap(self, name: str):
layers = [layer for layer in layers if layer["name"] != name]
self.layout.mapbox.layers = layers

def add_mapbox_layer(self, style: Union[str, Dict], access_token=None):
def add_mapbox_layer(self, style: Union[str, Dict], access_token=None) -> None:
"""Adds a mapbox layer to the map.
Args:
Expand All @@ -242,7 +242,7 @@ def add_layer(self, layer, name: Optional[str] = None, **kwargs):
layer.name = name
self.add_trace(layer, **kwargs)

def remove_layer(self, name: str):
def remove_layer(self, name: str) -> None:
"""Removes a layer from the map.
Args:
Expand Down Expand Up @@ -333,7 +333,7 @@ def find_layer_index(self, name: str) -> int:

return None

def set_layer_visibility(self, name: str, show: Optional[bool] = True):
def set_layer_visibility(self, name: str, show: Optional[bool] = True) -> None:
"""Sets the visibility of a layer.
Args:
Expand All @@ -350,7 +350,7 @@ def set_layer_visibility(self, name: str, show: Optional[bool] = True):
else:
print(f"Layer {name} not found.")

def set_layer_opacity(self, name: str, opacity: Optional[float] = 1):
def set_layer_opacity(self, name: str, opacity: Optional[float] = 1) -> None:
"""Sets the visibility of a layer.
Args:
Expand Down Expand Up @@ -378,7 +378,7 @@ def add_tile_layer(
attribution: Optional[str] = "",
opacity: Optional[float] = 1.0,
**kwargs,
):
) -> None:
"""Adds a TileLayer to the map.
Args:
Expand Down Expand Up @@ -408,7 +408,7 @@ def add_cog_layer(
bands: Optional[List] = None,
titiler_endpoint: Optional[str] = None,
**kwargs,
):
) -> None:
"""Adds a COG TileLayer to the map.
Args:
Expand Down Expand Up @@ -440,7 +440,7 @@ def add_stac_layer(
attribution: Optional[str] = "",
opacity: Optional[float] = 1.0,
**kwargs,
):
) -> None:
"""Adds a STAC TileLayer to the map.
Args:
Expand Down Expand Up @@ -469,7 +469,7 @@ def add_mosaic_layer(
attribution: Optional[str] = "",
opacity: Optional[float] = 1.0,
**kwargs,
):
) -> None:
"""Adds a STAC TileLayer to the map.
Args:
Expand All @@ -493,7 +493,7 @@ def add_planet_by_month(
name: Optional[str] = None,
attribution: str = "",
opacity: Optional[float] = 1.0,
):
) -> None:
"""Adds Planet global mosaic by month to the map. To get a Planet API key, see https://developers.planet.com/quickstart/apis/
Args:
Expand Down Expand Up @@ -521,7 +521,7 @@ def add_planet_by_quarter(
name: Optional[str] = None,
attribution: str = "",
opacity: Optional[float] = 1.0,
):
) -> None:
"""Adds Planet global mosaic by month to the map. To get a Planet API key, see https://developers.planet.com/quickstart/apis/
Args:
Expand All @@ -548,7 +548,7 @@ def save(
height: Optional[int] = None,
scale: Optional[int] = None,
**kwargs,
):
) -> None:
"""Convert a map to a static image and write it to a file or writeable object
Args:
Expand All @@ -569,7 +569,7 @@ def add_choropleth_map(
z: Optional[str] = None,
colorscale: Optional[str] = "Viridis",
**kwargs,
):
) -> None:
"""Adds a choropleth map to the map.
Args:
Expand All @@ -594,7 +594,7 @@ def add_choropleth_map(
**kwargs,
)

def add_scatter_plot_demo(self, **kwargs):
def add_scatter_plot_demo(self, **kwargs) -> None:
"""Adds a scatter plot to the map."""
lons = np.random.random(1000) * 360.0
lats = np.random.random(1000) * 180.0 - 90.0
Expand All @@ -613,7 +613,7 @@ def add_heatmap(
colorscale: Optional[str] = None,
name: Optional[str] = "Heat map",
**kwargs,
):
) -> None:
"""Adds a heat map to the map. Reference: https://plotly.com/python/mapbox-density-heatmaps
Args:
Expand Down Expand Up @@ -645,7 +645,7 @@ def add_heatmap(
)
self.add_trace(heatmap)

def add_heatmap_demo(self, **kwargs):
def add_heatmap_demo(self, **kwargs) -> None:
"""Adds a heatmap to the map."""
quakes = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv"
Expand Down Expand Up @@ -764,7 +764,7 @@ def add_geojson_layer(
name: str,
color: Optional[str] = "blue",
opacity: Optional[float] = 1,
):
) -> None:
"""Prepare proper and give style for different type of Geometry
Args:
Expand Down Expand Up @@ -809,7 +809,7 @@ def add_geojson(
type: Optional[str],
color: Optional[str],
opacity: Optional[float],
):
) -> None:
"""Add layers to the Map
Args:
Expand All @@ -835,7 +835,7 @@ def add_geojson(
self.update_layout(mapbox={"layers": tuple(existing_layers)})


def fix_widget_error():
def fix_widget_error() -> None:
"""
Fix FigureWidget - 'mapbox._derived' Value Error.
Adopted from: https://github.com/plotly/plotly.py/issues/2570#issuecomment-738735816
Expand Down

0 comments on commit f45cf5f

Please sign in to comment.