Skip to content

Commit 89f165c

Browse files
committed
Fix failing test and add optional default parameter
1 parent f3f5f07 commit 89f165c

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

functions-python/helpers/transform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def to_float(value, default_value: Optional[float] = None) -> Optional[float]:
8989
return default_value
9090

9191

92-
def get_safe_value(row, column_name, default_value):
92+
def get_safe_value(row, column_name, default_value=None) -> Optional[str]:
9393
"""
9494
Get a safe value from the row. If the value is missing or empty, return the default value.
9595
"""
@@ -101,7 +101,7 @@ def get_safe_value(row, column_name, default_value):
101101
return f"{value}".strip()
102102

103103

104-
def get_safe_float(row, column_name, default_value=None):
104+
def get_safe_float(row, column_name, default_value=None) -> Optional[float]:
105105
"""
106106
Get a safe float value from the row. If the value is missing or cannot be converted to float,
107107
"""

functions-python/pmtiles_builder/src/csv_cache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ def get_stops_from_trip(self, trip_id):
128128

129129
def get_coordinates_for_stop(self, stop_id) -> tuple[float, float] | None:
130130
if self.stop_to_coordinates is None:
131+
self.stop_to_coordinates = {}
131132
for s in self.get_file(STOPS_FILE):
133+
self.stop_to_coordinates.get(stop_id, [])
132134
row_stop_id = get_safe_value(s, "stop_id")
133135
row_stop_lon = get_safe_float(s, "stop_lon")
134136
row_stop_lat = get_safe_float(s, "stop_lat")
135137
if row_stop_id is None or row_stop_lon is None or row_stop_lat is None:
136138
self.logger.warning("Invalid stop data: %s", s)
137139
continue
138-
self.stop_to_coordinates = {row_stop_id: (row_stop_lon, row_stop_lat)}
140+
self.stop_to_coordinates[row_stop_id] = (row_stop_lon, row_stop_lat)
139141
return self.stop_to_coordinates.get(stop_id, None)
140142

141143
def set_workdir(self, workdir):

functions-python/pmtiles_builder/tests/test_build_pmtiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def test_create_routes_geojson_fallback_to_stop_coordinates(self):
391391
self.assertEqual(data["type"], "FeatureCollection")
392392
self.assertEqual(len(data["features"]), 1)
393393
coords = data["features"][0]["geometry"]["coordinates"]
394-
self.assertEqual(coords, [[-73.0, 45.0], [-73.1, 45.1]])
394+
self.assertEqual([[-73.0, 45.0], [-73.1, 45.1]], coords)
395395

396396
def test_load_agencies(self):
397397
builder = PmtilesBuilder("feed123", "feed123_dataset456")

0 commit comments

Comments
 (0)