@@ -278,11 +278,13 @@ def test_zip_to_state_id(self):
278
278
def test_add_population_column (self ):
279
279
gmpr = GeoMapper ()
280
280
new_data = gmpr .add_population_column (self .fips_data_3 , "fips" )
281
- assert new_data [ "population" ]. sum () == 274963
281
+ assert new_data . shape == ( 5 , 5 )
282
282
new_data = gmpr .add_population_column (self .zip_data , "zip" )
283
- assert new_data [ "population" ]. sum () == 274902
283
+ assert new_data . shape == ( 6 , 5 )
284
284
with pytest .raises (ValueError ):
285
285
new_data = gmpr .add_population_column (self .zip_data , "hrr" )
286
+ new_data = gmpr .add_population_column (self .fips_data_5 , "fips" )
287
+ assert new_data .shape == (4 , 5 )
286
288
287
289
def test_add_geocode (self ):
288
290
gmpr = GeoMapper ()
@@ -383,17 +385,19 @@ def test_add_geocode(self):
383
385
assert new_data2 ["hhs_region_number" ].unique ().size == 2
384
386
385
387
# state_name -> state_id
386
- new_data = gmpr .add_geocode (self .zip_data , "zip" , "state_name" )
388
+ new_data = gmpr .replace_geocode (self .zip_data , "zip" , "state_name" )
387
389
new_data2 = gmpr .add_geocode (new_data , "state_name" , "state_id" )
388
- assert new_data2 .shape == (12 , 6 )
390
+ assert new_data2 .shape == (4 , 5 )
391
+ new_data2 = gmpr .replace_geocode (new_data , "state_name" , "state_id" , new_col = "abbr" )
392
+ assert "abbr" in new_data2 .columns
389
393
390
394
# fips -> nation
391
- new_data = gmpr .replace_geocode (self .fips_data_5 , "fips" , "nation" )
395
+ new_data = gmpr .replace_geocode (self .fips_data_5 , "fips" , "nation" , new_col = "NATION" )
392
396
assert new_data .equals (
393
397
pd .DataFrame ().from_dict (
394
398
{
395
399
"date" : {0 : pd .Timestamp ("2018-01-01 00:00:00" )},
396
- "nation " : {0 : "us" },
400
+ "NATION " : {0 : "us" },
397
401
"count" : {0 : 10024.0 },
398
402
"total" : {0 : 100006.0 },
399
403
}
@@ -416,6 +420,23 @@ def test_add_geocode(self):
416
420
)
417
421
)
418
422
423
+ # hrr -> nation
424
+ with pytest .raises (ValueError ):
425
+ new_data = gmpr .replace_geocode (self .zip_data , "zip" , "hrr" )
426
+ new_data2 = gmpr .replace_geocode (new_data , "hrr" , "nation" )
427
+
428
+ # hrr -> nation
429
+ with pytest .raises (ValueError ):
430
+ new_data = gmpr .replace_geocode (self .zip_data , "zip" , "hrr" )
431
+ new_data2 = gmpr .replace_geocode (new_data , "hrr" , "nation" )
432
+
433
+ # hrr -> nation
434
+ with pytest .raises (ValueError ):
435
+ new_data = gmpr .replace_geocode (self .zip_data , "zip" , "hrr" )
436
+ new_data2 = gmpr .replace_geocode (new_data , "hrr" , "nation" )
437
+
419
438
# fips -> hrr (dropna=True/False check)
420
439
assert not gmpr .add_geocode (self .fips_data_3 , "fips" , "hrr" ).isna ().any ().any ()
421
440
assert gmpr .add_geocode (self .fips_data_3 , "fips" , "hrr" , dropna = False ).isna ().any ().any ()
441
+
442
+ TestGeoMapper ().test_add_geocode ()
0 commit comments