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

TYP: consistency in typing #567

Merged
merged 1 commit into from
Apr 15, 2024
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
7 changes: 3 additions & 4 deletions momepy/functional/_distribution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import geopandas as gpd
import numpy as np
import pandas as pd
import shapely
from geopandas import GeoDataFrame, GeoSeries
from libpysal.graph import Graph
Expand Down Expand Up @@ -119,7 +118,7 @@ def alignment(orientation: Series, graph: Graph) -> Series:

Parameters
----------
orientation : pd.Series
orientation : Series
A series containing orientation (e.g. measured by the :func:`orientation`
function) indexed using the same index that has been used to build the graph.
graph : libpysal.graph.Graph
Expand Down Expand Up @@ -197,7 +196,7 @@ def mean_interbuilding_distance(
-------
Series
"""
distance = pd.Series(
distance = Series(
shapely.distance(
geometry.geometry.loc[
adjacency_graph._adjacency.index.get_level_values(0)
Expand Down Expand Up @@ -295,7 +294,7 @@ def neighbors(

Parameters
----------
gdf : gpd.GeoDataFrame
gdf : GeoDataFrame | GeoSeries
GeoDataFrame containing geometries to analyse.
graph : libpysal.graph.Graph
Graph representing spatial relationships between elements.
Expand Down
45 changes: 21 additions & 24 deletions momepy/functional/_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import pandas as pd
import shapely
from geopandas import GeoDataFrame, GeoSeries
from joblib import Parallel, delayed
from libpysal.cg import voronoi_frames
from packaging.version import Version
Expand All @@ -20,15 +21,11 @@


def morphological_tessellation(
geometry: gpd.GeoSeries | gpd.GeoDataFrame,
clip: str
| shapely.Geometry
| gpd.GeoSeries
| gpd.GeoDataFrame
| None = "bounding_box",
geometry: GeoSeries | GeoDataFrame,
clip: str | shapely.Geometry | GeoSeries | GeoDataFrame | None = "bounding_box",
shrink: float = 0.4,
segment: float = 0.5,
) -> gpd.GeoSeries:
) -> GeoSeries:
"""Generate morphological tessellation.

Morpohological tessellation is a method to divide space into cells based on
Expand Down Expand Up @@ -56,9 +53,9 @@

Parameters
----------
geometry : gpd.GeoSeries | gpd.GeoDataFrame
geometry : GeoSeries | GeoDataFrame
A GeoDataFrame or GeoSeries containing buildings to tessellate the space around.
clip : str | shapely.Geometry | gpd.GeoSeries | gpd.GeoDataFrame | None
clip : str | shapely.Geometry | GeoSeries | GeoDataFrame | None
Polygon used to clip the Voronoi polygons, by default "bounding_box". You can
pass any option accepted by :func:`libpysal.cg.voronoi_frames` or geopandas
object that will be automatically unioned.
Expand All @@ -70,7 +67,7 @@

Returns
-------
gpd.GeoSeries
GeoSeries
GeoSeries with an index matching the index of input geometry

See also
Expand All @@ -79,7 +76,7 @@
momepy.CheckTessellationInput
momepy.verify_tessellation
"""
if isinstance(clip, gpd.GeoSeries | gpd.GeoDataFrame):
if isinstance(clip, GeoSeries | GeoDataFrame):
clip = clip.union_all() if GPD_GE_10 else clip.unary_union

return voronoi_frames(
Expand All @@ -93,13 +90,13 @@


def enclosed_tessellation(
geometry: gpd.GeoSeries | gpd.GeoDataFrame,
enclosures: gpd.GeoSeries,
geometry: GeoSeries | GeoDataFrame,
enclosures: GeoSeries,
shrink: float = 0.4,
segment: float = 0.5,
threshold: float = 0.05,
n_jobs: int = -1,
) -> gpd.GeoDataFrame:
) -> GeoDataFrame:
"""Generate enclosed tessellation

Enclosed tessellation is an enhanced :func:`morphological_tessellation`, based on
Expand Down Expand Up @@ -130,9 +127,9 @@

Parameters
----------
geometry : gpd.GeoSeries | gpd.GeoDataFrame
geometry : GeoSeries | GeoDataFrame
A GeoDataFrame or GeoSeries containing buildings to tessellate the space around.
enclosures : gpd.GeoSeries
enclosures : GeoSeries
The enclosures geometry, which can be generated using :func:`momepy.enclosures`.
shrink : float, optional
The distance for negative buffer to generate space between adjacent polygons).
Expand All @@ -151,7 +148,7 @@

Returns
-------
gpd.GeoDataFrame
GeoDataFrame
GeoDataFrame with an index matching the index of input geometry and a column
matching the index of input enclosures.

Expand Down Expand Up @@ -238,7 +235,7 @@
tess[enclosure_id] = ix
return tess

return gpd.GeoDataFrame(
return GeoDataFrame(

Check warning on line 238 in momepy/functional/_elements.py

View check run for this annotation

Codecov / codecov/patch

momepy/functional/_elements.py#L238

Added line #L238 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh. not currently covered?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah. Follow-up will come.

{enclosure_id: ix},
geometry=[poly],
index=[-1],
Expand All @@ -258,9 +255,9 @@

Parameters
----------
tesselation : gpd.GeoSeries | gpd.GeoDataFrame
tesselation : GeoSeries | GeoDataFrame
tessellation geometry
geometry : gpd.GeoSeries | gpd.GeoDataFrame
geometry : GeoSeries | GeoDataFrame
building geometry used to generate tessellation

Returns
Expand Down Expand Up @@ -299,17 +296,17 @@


def get_nearest_street(
buildings: gpd.GeoSeries | gpd.GeoDataFrame,
streets: gpd.GeoSeries | gpd.GeoDataFrame,
buildings: GeoSeries | GeoDataFrame,
streets: GeoSeries | GeoDataFrame,
max_distance: float | None = None,
) -> np.ndarray:
"""Identify the nearest street for each building.

Parameters
----------
buildings : gpd.GeoSeries | gpd.GeoDataFrame
buildings : GeoSeries | GeoDataFrame
GeoSeries or GeoDataFrame of buildings
streets : gpd.GeoSeries | gpd.GeoDataFrame
streets : GeoSeries | GeoDataFrame
GeoSeries or GeoDataFrame of streets
max_distance : float | None, optional
Maximum distance within which to query for nearest street. Must be
Expand Down
Loading