22
33import joblib
44from numpy import array
5- from numpy .testing import assert_array_equal , assert_equal
5+ from numpy .testing import assert_array_almost_equal , assert_equal
66from pandas import DataFrame , Timestamp
77from pandas .testing import assert_frame_equal
88from shapely .geometry import Polygon
@@ -64,7 +64,7 @@ def test_get_grid():
6464 'lat_min_y' : 39.984094 ,
6565 'grid_size_lat_y' : 5 ,
6666 'grid_size_lon_x' : 5 ,
67- 'cell_size_by_degree' : 0.0001353464801860623
67+ 'cell_size_by_degree' : 0.00013533905150922183
6868 }
6969 assert_equal (grid , expected )
7070
@@ -205,11 +205,11 @@ def test_convert_one_index_grid_to_two():
205205
206206def test_create_one_polygon_to_point_on_grid ():
207207 expected = [
208- [116.3193713464802 , 39.984094 ],
209- [116.3193713464802 , 39.984229346480184 ],
210- [116.31950669296039 , 39.984229346480184 ],
211- [116.31950669296039 , 39.984094 ],
212- [116.3193713464802 , 39.984094 ]
208+ [116.31937134 , 39.984094 ],
209+ [116.31937134 , 39.98422934 ],
210+ [116.31950668 , 39.98422934 ],
211+ [116.31950668 , 39.984094 ],
212+ [116.31937134 , 39.984094 ],
213213 ]
214214
215215 grid = _default_grid ()
@@ -218,7 +218,7 @@ def test_create_one_polygon_to_point_on_grid():
218218
219219 polygon_coordinates = array (polygon .exterior .coords )
220220
221- assert_array_equal (polygon_coordinates , expected )
221+ assert_array_almost_equal (polygon_coordinates , expected )
222222
223223
224224def test_create_all_polygons_to_all_point_on_grid ():
@@ -227,48 +227,25 @@ def test_create_all_polygons_to_all_point_on_grid():
227227 [
228228 1 , 0 , 0 , Polygon ((
229229 (116.319236 , 39.984094 ),
230- (116.319236 , 39.984229346480184 ),
231- (116.3193713464802 , 39.984229346480184 ),
232- (116.3193713464802 , 39.984094 ),
230+ (116.319236 , 39.98422933905151 ),
231+ (116.3193713390515 , 39.98422933905151 ),
232+ (116.3193713390515 , 39.984094 ),
233233 (116.319236 , 39.984094 )
234234 ))
235- ],
236- [
237- 1 , 0 , 1 , Polygon ((
238- (116.3193713464802 , 39.984094 ),
239- (116.3193713464802 , 39.984229346480184 ),
240- (116.31950669296039 , 39.984229346480184 ),
241- (116.31950669296039 , 39.984094 ),
242- (116.3193713464802 , 39.984094 )
243- ))
244- ],
245- [
246- 1 , 4 , 4 , Polygon ((
247- (116.31977738592074 , 39.98463538592074 ),
248- (116.31977738592074 , 39.984770732400925 ),
249- (116.31991273240094 , 39.984770732400925 ),
250- (116.31991273240094 , 39.98463538592074 ),
251- (116.31977738592074 , 39.98463538592074 )
252- ))
253- ],
254- [
255- 1 , 3 , 3 , Polygon ((
256- (116.31964203944057 , 39.984500039440555 ),
257- (116.31964203944057 , 39.98463538592074 ),
258- (116.31977738592076 , 39.98463538592074 ),
259- (116.31977738592076 , 39.984500039440555 ),
260- (116.31964203944057 , 39.984500039440555 )
261- ))
262- ],
235+ ]
263236 ],
264237 columns = ['id' , 'index_grid_lat' , 'index_grid_lon' , 'polygon' ],
265- index = [0 , 2 , 5 , 7 ],
238+ index = [0 ],
266239 )
267240 move_df = _default_move_df ()
241+ move_df = move_df [move_df .index == 0 ]
268242 grid = Grid (move_df , 15 )
269243
270244 all_polygon = grid .create_all_polygons_to_all_point_on_grid (move_df )
271- assert_frame_equal (all_polygon , expected )
245+
246+ a = all_polygon .iloc [0 ]['polygon' ].exterior .xy
247+ b = expected .iloc [0 ]['polygon' ].exterior .xy
248+ assert_array_almost_equal (a , b )
272249
273250
274251def test_point_to_index_grid ():
@@ -288,7 +265,7 @@ def test_save_grid_pkl(tmpdir):
288265 'lat_min_y' : 39.984094 ,
289266 'grid_size_lat_y' : 5 ,
290267 'grid_size_lon_x' : 5 ,
291- 'cell_size_by_degree' : 0.0001353464801860623
268+ 'cell_size_by_degree' : 0.00013533905150922183
292269 }
293270 d = tmpdir .mkdir ('core' )
294271
0 commit comments