@@ -331,53 +331,123 @@ def test_from_geodataframe_default(self, gdf):
331
331
assert {k : list (v .values ) for k , v in cube .coords .items ()} == {"geometries" : [0 , 1 ], "properties" : ["pop" ]}
332
332
333
333
@pytest .mark .parametrize (
334
- ["columns_for_cube" , "expected " ],
334
+ ["columns_for_cube" , "expected_cube " ],
335
335
[
336
- ("numerical" , {"shape" : (2 , 1 ), "coords" : {"geometries" : [0 , 1 ], "properties" : ["pop" ]}}),
337
- ("all" , {"shape" : (2 , 2 ), "coords" : {"geometries" : [0 , 1 ], "properties" : ["id" , "pop" ]}}),
336
+ (
337
+ "numerical" ,
338
+ {
339
+ "name" : None ,
340
+ "dims" : ("geometries" , "properties" ),
341
+ "coords" : {
342
+ "geometries" : {"attrs" : {}, "data" : [0 , 1 ], "dims" : ("geometries" ,)},
343
+ "properties" : {"attrs" : {}, "data" : ["pop" ], "dims" : ("properties" ,)},
344
+ },
345
+ "data" : [[1234 ], [5678 ]],
346
+ "attrs" : {},
347
+ },
348
+ ),
349
+ (
350
+ "all" ,
351
+ {
352
+ "name" : None ,
353
+ "dims" : ("geometries" , "properties" ),
354
+ "coords" : {
355
+ "geometries" : {"attrs" : {}, "data" : [0 , 1 ], "dims" : ("geometries" ,)},
356
+ "properties" : {"attrs" : {}, "data" : ["id" , "pop" ], "dims" : ("properties" ,)},
357
+ },
358
+ "data" : [["first" , 1234 ], ["second" , 5678 ]],
359
+ "attrs" : {},
360
+ },
361
+ ),
338
362
([], None ),
339
- (["id" ], {"shape" : (2 , 1 ), "coords" : {"geometries" : [0 , 1 ], "properties" : ["id" ]}}),
340
- (["pop" , "id" ], {"shape" : (2 , 2 ), "coords" : {"geometries" : [0 , 1 ], "properties" : ["pop" , "id" ]}}),
341
- # TODO: test specifying non-existent column (to be filled with no-data):
342
- # (["pop", "nopenope"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["pop", "nopenope"]}}),
363
+ (
364
+ ["id" ],
365
+ {
366
+ "name" : None ,
367
+ "dims" : ("geometries" , "properties" ),
368
+ "coords" : {
369
+ "geometries" : {"attrs" : {}, "data" : [0 , 1 ], "dims" : ("geometries" ,)},
370
+ "properties" : {"attrs" : {}, "data" : ["id" ], "dims" : ("properties" ,)},
371
+ },
372
+ "data" : [["first" ], ["second" ]],
373
+ "attrs" : {},
374
+ },
375
+ ),
376
+ (
377
+ ["pop" , "id" ],
378
+ {
379
+ "name" : None ,
380
+ "dims" : ("geometries" , "properties" ),
381
+ "coords" : {
382
+ "geometries" : {"attrs" : {}, "data" : [0 , 1 ], "dims" : ("geometries" ,)},
383
+ "properties" : {"attrs" : {}, "data" : ["pop" , "id" ], "dims" : ("properties" ,)},
384
+ },
385
+ "data" : [[1234 , "first" ], [5678 , "second" ]],
386
+ "attrs" : {},
387
+ },
388
+ ),
389
+ (
390
+ ["color" ],
391
+ {
392
+ "name" : None ,
393
+ "dims" : ("geometries" , "properties" ),
394
+ "coords" : {
395
+ "geometries" : {"attrs" : {}, "data" : [0 , 1 ], "dims" : ("geometries" ,)},
396
+ "properties" : {"attrs" : {}, "data" : ["color" ], "dims" : ("properties" ,)},
397
+ },
398
+ "data" : [[IsNan ()], [IsNan ()]],
399
+ "attrs" : {},
400
+ },
401
+ ),
402
+ (
403
+ ["pop" , "color" ],
404
+ {
405
+ "name" : None ,
406
+ "dims" : ("geometries" , "properties" ),
407
+ "coords" : {
408
+ "geometries" : {"attrs" : {}, "data" : [0 , 1 ], "dims" : ("geometries" ,)},
409
+ "properties" : {"attrs" : {}, "data" : ["pop" , "color" ], "dims" : ("properties" ,)},
410
+ },
411
+ "data" : [[1234 , IsNan ()], [5678 , IsNan ()]],
412
+ "attrs" : {},
413
+ },
414
+ ),
343
415
],
344
416
)
345
- def test_from_geodataframe_columns_for_cube (self , gdf , columns_for_cube , expected ):
417
+ def test_from_geodataframe_columns_for_cube (self , gdf , columns_for_cube , expected_cube ):
346
418
vc = DriverVectorCube .from_geodataframe (gdf , columns_for_cube = columns_for_cube )
347
- assert vc .to_geojson () == DictSubSet (
348
- {
349
- "type" : "FeatureCollection" ,
350
- "features" : [
351
- DictSubSet (
352
- {
353
- "type" : "Feature" ,
354
- "properties" : {"id" : "first" , "pop" : 1234 },
355
- "geometry" : {
356
- "coordinates" : (((1.0 , 1.0 ), (3.0 , 1.0 ), (2.0 , 3.0 ), (1.0 , 1.0 )),),
357
- "type" : "Polygon" ,
358
- },
359
- }
360
- ),
361
- DictSubSet (
362
- {
363
- "type" : "Feature" ,
364
- "properties" : {"id" : "second" , "pop" : 5678 },
365
- "geometry" : {
366
- "coordinates" : (((4.0 , 2.0 ), (5.0 , 4.0 ), (3.0 , 4.0 ), (4.0 , 2.0 )),),
367
- "type" : "Polygon" ,
368
- },
369
- }
370
- ),
371
- ],
372
- }
373
- )
374
- cube = vc .get_cube ()
375
- if expected is None :
376
- assert cube is None
377
- else :
378
- assert cube .dims == ("geometries" , "properties" )
379
- assert cube .shape == expected ["shape" ]
380
- assert {k : list (v .values ) for k , v in cube .coords .items ()} == expected ["coords" ]
419
+
420
+ assert vc .to_internal_json () == {
421
+ "geometries" : DictSubSet (
422
+ {
423
+ "type" : "FeatureCollection" ,
424
+ "features" : [
425
+ DictSubSet (
426
+ {
427
+ "type" : "Feature" ,
428
+ "geometry" : {
429
+ "type" : "Polygon" ,
430
+ "coordinates" : (((1.0 , 1.0 ), (3.0 , 1.0 ), (2.0 , 3.0 ), (1.0 , 1.0 )),),
431
+ },
432
+ "properties" : {"id" : "first" , "pop" : 1234 },
433
+ }
434
+ ),
435
+ DictSubSet (
436
+ {
437
+ "type" : "Feature" ,
438
+ "geometry" : {
439
+ "type" : "Polygon" ,
440
+ "coordinates" : (((4.0 , 2.0 ), (5.0 , 4.0 ), (3.0 , 4.0 ), (4.0 , 2.0 )),),
441
+ },
442
+ "properties" : {"id" : "second" , "pop" : 5678 },
443
+ }
444
+ ),
445
+ ],
446
+ }
447
+ ),
448
+ "cube" : expected_cube ,
449
+ }
450
+
381
451
382
452
@pytest .mark .parametrize (["geojson" , "expected" ], [
383
453
(
0 commit comments