Skip to content

Commit

Permalink
apply PR comments:
Browse files Browse the repository at this point in the history
- add extra test for saving empty geodataframes
- remove remaining `Optional[] != None`
- lint
  • Loading branch information
KasiaKoz committed May 28, 2024
1 parent 45e29b0 commit 3cdd9c1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/genet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 3 additions & 8 deletions src/genet/output/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import math
import os
from itertools import chain
from typing import Optional

import geopandas as gpd
import pandas as pd
Expand Down Expand Up @@ -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,
):
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/genet/schedule_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/genet/utils/io.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/test_utils_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3cdd9c1

Please sign in to comment.