diff --git a/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py b/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py index 4b6943fd..44357755 100644 --- a/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py +++ b/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py @@ -134,17 +134,15 @@ def coordinate_download( for col in target_columns: if col not in downloaded_metadata.columns: downloaded_metadata[col] = None - if ( downloaded_metadata.isna().all().all() is False - or downloaded_metadata.empty is True + or downloaded_metadata.empty is False ): downloaded_metadata = downloaded_metadata[ downloaded_metadata["geometry"].apply( lambda point: point.within(polygon) ) ] - return downloaded_metadata diff --git a/mapswipe_workers/tests/unittests/test_process_mapillary.py b/mapswipe_workers/tests/unittests/test_process_mapillary.py index 8134ad2b..1913ccb4 100644 --- a/mapswipe_workers/tests/unittests/test_process_mapillary.py +++ b/mapswipe_workers/tests/unittests/test_process_mapillary.py @@ -5,7 +5,7 @@ import pandas as pd from shapely import wkt -from shapely.geometry import GeometryCollection, MultiPolygon, Polygon +from shapely.geometry import GeometryCollection, MultiPolygon, Point, Polygon from mapswipe_workers.utils.process_mapillary import ( coordinate_download, @@ -191,10 +191,30 @@ def test_download_and_process_tile_failure(self, mock_get): @patch("mapswipe_workers.utils.process_mapillary.download_and_process_tile") def test_coordinate_download(self, mock_download_and_process_tile): - mock_download_and_process_tile.return_value = pd.DataFrame([{"geometry": None}]) + inside_points = [ + (0.2, 0.2), + (0.5, 0.5), + ] + outside_points = [ + (1.5, 0.5), + (0.5, 1.5), + (-0.5, 0.5), + ] + points = inside_points + outside_points + data = [ + { + "geometry": Point(x, y), + } + for x, y in points + ] + + mock_download_and_process_tile.return_value = pd.DataFrame(data) metadata = coordinate_download(self.test_polygon, self.level) + metadata = metadata.drop_duplicates() + self.assertEqual(len(metadata), len(inside_points)) + self.assertIsInstance(metadata, pd.DataFrame) @patch("mapswipe_workers.utils.process_mapillary.download_and_process_tile")