Skip to content

Commit

Permalink
refactor: Add type defence for in_pth & out_pth
Browse files Browse the repository at this point in the history
  • Loading branch information
r-leyshon committed Sep 20, 2023
1 parent 70ec84c commit fa368b3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/transport_performance/gtfs/gtfs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def bbox_filter_gtfs(
in_pth: Union[pathlib.Path, str] = here(
"tests/data/newport-20230613_gtfs.zip"
),
out_pth: Union[pathlib.Path, str] = here(
"data/external/filtered_gtfs.zip"
out_pth: Union[pathlib.Path, str] = pathlib.Path(
here("data/external/filtered_gtfs.zip")
),
bbox: Union[GeoDataFrame, list] = [
-3.077081,
Expand Down Expand Up @@ -56,18 +56,22 @@ def bbox_filter_gtfs(
None
"""
_is_expected_filetype(pth=in_pth, param_nm="in_pth")
_is_expected_filetype(
pth=out_pth, param_nm="out_pth", check_existing=False
)
typing_dict = {
"bbox": [bbox, (list, GeoDataFrame)],
"units": [units, str],
"crs": [crs, str],
"out_pth": [out_pth, (str, pathlib.Path)],
"in_pth": [in_pth, (str, pathlib.Path)],
}
for k, v in typing_dict.items():
_type_defence(v[0], k, v[-1])

# check paths have valid zip extensions
_is_expected_filetype(pth=in_pth, param_nm="in_pth")
_is_expected_filetype(
pth=out_pth, param_nm="out_pth", check_existing=False
)

if isinstance(bbox, list):
_check_list(ls=bbox, param_nm="bbox_list", exp_type=float)
# create box polygon around provided coords, need to splat
Expand Down

0 comments on commit fa368b3

Please sign in to comment.