Skip to content

Commit 263d738

Browse files
committed
fix: do not return failed_rows and do not use functions on empty df
1 parent 6a1d15e commit 263d738

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

mapswipe_workers/mapswipe_workers/utils/process_mapillary.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def coordinate_download(
125125
if len(downloaded_metadata):
126126
downloaded_metadata = pd.concat(downloaded_metadata, ignore_index=True)
127127
else:
128-
downloaded_metadata = pd.DataFrame(downloaded_metadata)
128+
return pd.DataFrame(downloaded_metadata)
129129

130130
failed_tiles = pd.DataFrame(failed_tiles, columns=tiles.columns).reset_index(
131131
drop=True
@@ -137,11 +137,12 @@ def coordinate_download(
137137
if col not in downloaded_metadata.columns:
138138
downloaded_metadata[col] = None
139139

140-
downloaded_metadata = downloaded_metadata[
141-
downloaded_metadata['geometry'].apply(lambda point: point.within(polygon))
142-
]
140+
if downloaded_metadata.isna().all().all() == False or downloaded_metadata.empty == True:
141+
downloaded_metadata = downloaded_metadata[
142+
downloaded_metadata['geometry'].apply(lambda point: point.within(polygon))
143+
]
143144

144-
return downloaded_metadata, failed_tiles
145+
return downloaded_metadata
145146

146147

147148
def geojson_to_polygon(geojson_data):
@@ -226,7 +227,7 @@ def get_image_metadata(
226227
sampling_threshold = None,
227228
):
228229
aoi_polygon = geojson_to_polygon(aoi_geojson)
229-
downloaded_metadata, failed_tiles = coordinate_download(
230+
downloaded_metadata = coordinate_download(
230231
aoi_polygon, level, attempt_limit
231232
)
232233
downloaded_metadata = downloaded_metadata[

mapswipe_workers/tests/unittests/test_process_mapillary.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_coordinate_download(self, mock_download_and_process_tile):
200200
None,
201201
)
202202

203-
metadata, failed = coordinate_download(
203+
metadata = coordinate_download(
204204
self.test_polygon, self.level
205205
)
206206

@@ -214,12 +214,11 @@ def test_coordinate_download_with_failures(self, mock_download_and_process_tile)
214214
pd.Series({"x": 1, "y": 1, "z": self.level}),
215215
)
216216

217-
metadata, failed = coordinate_download(
217+
metadata = coordinate_download(
218218
self.test_polygon, self.level
219219
)
220220

221221
self.assertTrue(metadata.empty)
222-
self.assertFalse(failed.empty)
223222

224223
def test_filter_within_time_range(self):
225224
start_time = "2016-01-20 00:00:00"
@@ -284,10 +283,7 @@ def test_filter_missing_columns(self):
284283

285284
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
286285
def test_get_image_metadata(self, mock_coordinate_download):
287-
mock_coordinate_download.return_value = (
288-
self.fixture_df,
289-
None,
290-
)
286+
mock_coordinate_download.return_value = self.fixture_df
291287
result = get_image_metadata(self.fixture_data)
292288
self.assertIsInstance(result, dict)
293289
self.assertIn("ids", result)
@@ -296,10 +292,7 @@ def test_get_image_metadata(self, mock_coordinate_download):
296292

297293
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
298294
def test_get_image_metadata_filtering(self, mock_coordinate_download):
299-
mock_coordinate_download.return_value = (
300-
self.fixture_df,
301-
None,
302-
)
295+
mock_coordinate_download.return_value = self.fixture_df
303296

304297
params = {
305298
"is_pano": True,
@@ -315,10 +308,7 @@ def test_get_image_metadata_filtering(self, mock_coordinate_download):
315308

316309
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
317310
def test_get_image_metadata_no_rows(self, mock_coordinate_download):
318-
mock_coordinate_download.return_value = (
319-
self.fixture_df,
320-
None,
321-
)
311+
mock_coordinate_download.return_value = self.fixture_df
322312

323313
params = {
324314
"is_pano": True,
@@ -332,10 +322,7 @@ def test_get_image_metadata_no_rows(self, mock_coordinate_download):
332322
def test_get_image_metadata_empty_response(self, mock_coordinate_download):
333323
df = self.fixture_df.copy()
334324
df = df.drop(df.index)
335-
mock_coordinate_download.return_value = (
336-
df,
337-
None
338-
)
325+
mock_coordinate_download.return_value = df
339326

340327
with self.assertRaises(ValueError):
341328
get_image_metadata(self.fixture_data)
@@ -344,10 +331,7 @@ def test_get_image_metadata_empty_response(self, mock_coordinate_download):
344331
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
345332
def test_get_image_metadata_size_restriction(self, mock_coordinate_download, mock_filter_results):
346333
mock_filter_results.return_value = pd.DataFrame({'ID': range(1, 100002)})
347-
mock_coordinate_download.return_value = (
348-
self.fixture_df,
349-
None,
350-
)
334+
mock_coordinate_download.return_value = self.fixture_df
351335

352336
with self.assertRaises(ValueError):
353337
get_image_metadata(self.fixture_data)

0 commit comments

Comments
 (0)