Skip to content

Commit

Permalink
fix: do not return failed_rows and do not use functions on empty df
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigaszi committed Nov 28, 2024
1 parent 6a1d15e commit 263d738
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
13 changes: 7 additions & 6 deletions mapswipe_workers/mapswipe_workers/utils/process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def coordinate_download(
if len(downloaded_metadata):
downloaded_metadata = pd.concat(downloaded_metadata, ignore_index=True)
else:
downloaded_metadata = pd.DataFrame(downloaded_metadata)
return pd.DataFrame(downloaded_metadata)

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

downloaded_metadata = downloaded_metadata[
downloaded_metadata['geometry'].apply(lambda point: point.within(polygon))
]
if downloaded_metadata.isna().all().all() == False or downloaded_metadata.empty == True:
downloaded_metadata = downloaded_metadata[
downloaded_metadata['geometry'].apply(lambda point: point.within(polygon))
]

return downloaded_metadata, failed_tiles
return downloaded_metadata


def geojson_to_polygon(geojson_data):
Expand Down Expand Up @@ -226,7 +227,7 @@ def get_image_metadata(
sampling_threshold = None,
):
aoi_polygon = geojson_to_polygon(aoi_geojson)
downloaded_metadata, failed_tiles = coordinate_download(
downloaded_metadata = coordinate_download(
aoi_polygon, level, attempt_limit
)
downloaded_metadata = downloaded_metadata[
Expand Down
30 changes: 7 additions & 23 deletions mapswipe_workers/tests/unittests/test_process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_coordinate_download(self, mock_download_and_process_tile):
None,
)

metadata, failed = coordinate_download(
metadata = coordinate_download(
self.test_polygon, self.level
)

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

metadata, failed = coordinate_download(
metadata = coordinate_download(
self.test_polygon, self.level
)

self.assertTrue(metadata.empty)
self.assertFalse(failed.empty)

def test_filter_within_time_range(self):
start_time = "2016-01-20 00:00:00"
Expand Down Expand Up @@ -284,10 +283,7 @@ def test_filter_missing_columns(self):

@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
def test_get_image_metadata(self, mock_coordinate_download):
mock_coordinate_download.return_value = (
self.fixture_df,
None,
)
mock_coordinate_download.return_value = self.fixture_df
result = get_image_metadata(self.fixture_data)
self.assertIsInstance(result, dict)
self.assertIn("ids", result)
Expand All @@ -296,10 +292,7 @@ def test_get_image_metadata(self, mock_coordinate_download):

@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
def test_get_image_metadata_filtering(self, mock_coordinate_download):
mock_coordinate_download.return_value = (
self.fixture_df,
None,
)
mock_coordinate_download.return_value = self.fixture_df

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

@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
def test_get_image_metadata_no_rows(self, mock_coordinate_download):
mock_coordinate_download.return_value = (
self.fixture_df,
None,
)
mock_coordinate_download.return_value = self.fixture_df

params = {
"is_pano": True,
Expand All @@ -332,10 +322,7 @@ def test_get_image_metadata_no_rows(self, mock_coordinate_download):
def test_get_image_metadata_empty_response(self, mock_coordinate_download):
df = self.fixture_df.copy()
df = df.drop(df.index)
mock_coordinate_download.return_value = (
df,
None
)
mock_coordinate_download.return_value = df

with self.assertRaises(ValueError):
get_image_metadata(self.fixture_data)
Expand All @@ -344,10 +331,7 @@ def test_get_image_metadata_empty_response(self, mock_coordinate_download):
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
def test_get_image_metadata_size_restriction(self, mock_coordinate_download, mock_filter_results):
mock_filter_results.return_value = pd.DataFrame({'ID': range(1, 100002)})
mock_coordinate_download.return_value = (
self.fixture_df,
None,
)
mock_coordinate_download.return_value = self.fixture_df

with self.assertRaises(ValueError):
get_image_metadata(self.fixture_data)
Expand Down

0 comments on commit 263d738

Please sign in to comment.