Skip to content

Commit b9e0a49

Browse files
committed
fix: change test to match new code
1 parent 3f09ae7 commit b9e0a49

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed
Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
import os
2-
32
import unittest
3+
44
import numpy as np
55
import pandas as pd
66
from shapely import wkt
77
from shapely.geometry import Point
88

9-
from mapswipe_workers.utils.spatial_sampling import distance_on_sphere, filter_points, spatial_sampling
9+
from mapswipe_workers.utils.spatial_sampling import (
10+
distance_on_sphere,
11+
filter_points,
12+
spatial_sampling,
13+
)
1014

1115

1216
class TestDistanceCalculations(unittest.TestCase):
13-
1417
@classmethod
1518
def setUpClass(cls):
1619
with open(
17-
os.path.join(
18-
os.path.dirname(os.path.abspath(__file__)),
19-
"..",
20-
"fixtures",
21-
"mapillary_sequence.csv",
22-
),
23-
"r",
20+
os.path.join(
21+
os.path.dirname(os.path.abspath(__file__)),
22+
"..",
23+
"fixtures",
24+
"mapillary_sequence.csv",
25+
),
26+
"r",
2427
) as file:
2528
df = pd.read_csv(file)
26-
df['geometry'] = df['geometry'].apply(wkt.loads)
29+
df["geometry"] = df["geometry"].apply(wkt.loads)
2730

2831
cls.fixture_df = df
2932

@@ -42,41 +45,43 @@ def test_filter_points(self):
4245
"POINT (-74.006 40.7128)",
4346
"POINT (-75.006 41.7128)",
4447
"POINT (-76.006 42.7128)",
45-
"POINT (-77.006 43.7128)"
48+
"POINT (-77.006 43.7128)",
4649
]
4750
}
4851
df = pd.DataFrame(data)
4952

50-
df['geometry'] = df['geometry'].apply(wkt.loads)
53+
df["geometry"] = df["geometry"].apply(wkt.loads)
5154

52-
df['long'] = df['geometry'].apply(lambda geom: geom.x if geom.geom_type == 'Point' else None)
53-
df['lat'] = df['geometry'].apply(lambda geom: geom.y if geom.geom_type == 'Point' else None)
55+
df["long"] = df["geometry"].apply(
56+
lambda geom: geom.x if geom.geom_type == "Point" else None
57+
)
58+
df["lat"] = df["geometry"].apply(
59+
lambda geom: geom.y if geom.geom_type == "Point" else None
60+
)
5461
threshold_distance = 100
5562
filtered_df = filter_points(df, threshold_distance)
5663

5764
self.assertIsInstance(filtered_df, pd.DataFrame)
5865
self.assertLessEqual(len(filtered_df), len(df))
5966

60-
6167
def test_spatial_sampling_ordering(self):
6268
data = {
6369
"geometry": [
6470
"POINT (-74.006 40.7128)",
6571
"POINT (-75.006 41.7128)",
6672
"POINT (-76.006 42.7128)",
67-
"POINT (-77.006 43.7128)"
73+
"POINT (-77.006 43.7128)",
6874
],
69-
'captured_at': [1, 2, 3, 4],
70-
'sequence_id': ['1', '1', '1', '1']
75+
"captured_at": [1, 2, 3, 4],
76+
"sequence_id": ["1", "1", "1", "1"],
7177
}
7278
df = pd.DataFrame(data)
73-
df['geometry'] = df['geometry'].apply(wkt.loads)
79+
df["geometry"] = df["geometry"].apply(wkt.loads)
7480

7581
interval_length = 0.1
7682
filtered_gdf = spatial_sampling(df, interval_length)
7783

78-
self.assertTrue(filtered_gdf['captured_at'].is_monotonic_increasing)
79-
84+
self.assertTrue(filtered_gdf["captured_at"].is_monotonic_decreasing)
8085

8186
def test_spatial_sampling_with_sequence(self):
8287
threshold_distance = 0.01
@@ -86,15 +91,13 @@ def test_spatial_sampling_with_sequence(self):
8691

8792
filtered_df.reset_index(drop=True, inplace=True)
8893
for i in range(len(filtered_df) - 1):
89-
geom1 = filtered_df.loc[i, 'geometry']
90-
geom2 = filtered_df.loc[i + 1, 'geometry']
94+
geom1 = filtered_df.loc[i, "geometry"]
95+
geom2 = filtered_df.loc[i + 1, "geometry"]
9196

9297
distance = geom1.distance(geom2)
9398

9499
self.assertLess(distance, threshold_distance)
95100

96101

97-
98-
99102
if __name__ == "__main__":
100103
unittest.main()

0 commit comments

Comments
 (0)