diff --git a/src/genet/core.py b/src/genet/core.py index 05d562e4..df40f14f 100644 --- a/src/genet/core.py +++ b/src/genet/core.py @@ -3015,7 +3015,7 @@ def write_to_json(self, output_dir: str): self.schedule.write_to_json(output_dir) self.write_extras(output_dir) - def write_spatial(self, output_dir, epsg: str = None, filetype: Optional[str] = "parquet"): + def write_spatial(self, output_dir, epsg: Optional[str] = None, filetype: str = "parquet"): """Transforms Network and Schedule (if applicable) to geopandas.GeoDataFrame of nodes and links and saves to the requested file format. diff --git a/src/genet/output/spatial.py b/src/genet/output/spatial.py index 3f65d472..98831c9c 100644 --- a/src/genet/output/spatial.py +++ b/src/genet/output/spatial.py @@ -3,7 +3,6 @@ import math import os from itertools import chain -from typing import Optional import geopandas as gpd import pandas as pd @@ -63,8 +62,8 @@ def line_geometry(): def generate_standard_outputs_for_schedule( schedule, output_dir: str, - gtfs_day: Optional[str] = "19700101", - filetype: Optional[str] = "parquet", + gtfs_day: str = "19700101", + filetype: str = "parquet", schedule_network_factor=1.3, gdf_network_links=None, ): @@ -204,11 +203,7 @@ def generate_standard_outputs_for_schedule( def generate_standard_outputs( - n, - output_dir, - gtfs_day="19700101", - filetype: Optional[str] = "parquet", - schedule_network_factor=1.3, + n, output_dir, gtfs_day="19700101", filetype: str = "parquet", schedule_network_factor=1.3 ): """Generates spatial files that can be used for generating standard visualisations. diff --git a/src/genet/schedule_elements.py b/src/genet/schedule_elements.py index a9274f9d..e8b126e3 100644 --- a/src/genet/schedule_elements.py +++ b/src/genet/schedule_elements.py @@ -3698,7 +3698,7 @@ def write_to_json(self, output_dir: str): json.dump(self.to_json(), outfile) self.write_extras(output_dir) - def write_spatial(self, output_dir, epsg: str = None, filetype: str = "parquet"): + def write_spatial(self, output_dir, epsg: Optional[str] = None, filetype: str = "parquet"): """Transforms Schedule (if applicable) to geopandas.GeoDataFrame of nodes and links and saves to the requested file format. diff --git a/src/genet/utils/io.py b/src/genet/utils/io.py index 00faece8..fb98da68 100644 --- a/src/genet/utils/io.py +++ b/src/genet/utils/io.py @@ -1,5 +1,4 @@ import os -from typing import Optional import geopandas as gpd from pandas.core.dtypes.common import is_datetime64_any_dtype as is_datetime diff --git a/tests/test_utils_io.py b/tests/test_utils_io.py index 29623d1b..808992fd 100644 --- a/tests/test_utils_io.py +++ b/tests/test_utils_io.py @@ -13,6 +13,17 @@ def test_throws_error_when_filetype_is_not_supported(): assert "is not a supported file type" in str(e.value) +def test_saving_empty_geodataframe_does_not_produce_file(tmpdir): + expected_file_name = "tmp" + expected_output_path = tmpdir / expected_file_name + ".parquet" + assert not os.path.exists(expected_output_path) + + gdf = GeoDataFrame(columns=["id", "geometry"]) + genet.utils.io.save_geodataframe(gdf, filename=expected_file_name, output_dir=tmpdir) + + assert not os.path.exists(expected_output_path) + + def test_saving_geodataframe_with_missing_geometry_produces_file(tmpdir): expected_file_name = "tmp" expected_output_path = tmpdir / expected_file_name + ".parquet"