@@ -1446,6 +1446,47 @@ def cohort_data_expected_columns():
14461446 }
14471447
14481448
1449+ def cohort_data_admin1_year_expected_columns ():
1450+ return {
1451+ "cohort_id" : "O" ,
1452+ "cohort_size" : "i" ,
1453+ "country" : "O" ,
1454+ "country_alpha2" : "O" ,
1455+ "country_alpha3" : "O" ,
1456+ "taxon" : "O" ,
1457+ "year" : "i" ,
1458+ "admin1_name" : "O" ,
1459+ "admin1_iso" : "O" ,
1460+ "admin1_geoboundaries_shape_id" : "O" ,
1461+ "admin1_representative_longitude" : "f" ,
1462+ "admin1_representative_latitude" : "f" ,
1463+ }
1464+
1465+
1466+ def cohort_data_admin2_month_expected_columns ():
1467+ return {
1468+ "cohort_id" : "O" ,
1469+ "cohort_size" : "i" ,
1470+ "country" : "O" ,
1471+ "country_alpha2" : "O" ,
1472+ "country_alpha3" : "O" ,
1473+ "taxon" : "O" ,
1474+ "year" : "i" ,
1475+ "quarter" : "i" ,
1476+ "month" : "i" ,
1477+ "admin1_name" : "O" ,
1478+ "admin1_iso" : "O" ,
1479+ "admin1_geoboundaries_shape_id" : "O" ,
1480+ "admin1_representative_longitude" : "f" ,
1481+ "admin1_representative_latitude" : "f" ,
1482+ "admin2_name" : "O" ,
1483+ "admin2_iso" : "O" ,
1484+ "admin2_geoboundaries_shape_id" : "O" ,
1485+ "admin2_representative_longitude" : "f" ,
1486+ "admin2_representative_latitude" : "f" ,
1487+ }
1488+
1489+
14491490def validate_cohort_data (df , expected_columns ):
14501491 # Check column names.
14511492 # Note: insertion order in dictionary keys is guaranteed since Python 3.7
@@ -1467,6 +1508,40 @@ def test_cohort_data(fixture, api):
14671508 validate_cohort_data (df_cohorts , cohort_data_expected_columns ())
14681509
14691510
1511+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1512+ def test_cohort_data_admin1_year (fixture , api ):
1513+ df_cohorts = api .cohorts ("admin1_year" )
1514+ validate_cohort_data (df_cohorts , cohort_data_admin1_year_expected_columns ())
1515+
1516+
1517+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1518+ def test_cohort_data_admin2_month (fixture , api ):
1519+ df_cohorts = api .cohorts ("admin2_month" )
1520+ validate_cohort_data (df_cohorts , cohort_data_admin2_month_expected_columns ())
1521+
1522+
1523+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1524+ def test_cohort_data_invalid_cohort_set (fixture , api ):
1525+ with pytest .raises (ValueError , match = "is not a valid cohort set" ):
1526+ api .cohorts ("invalid_name" )
1527+
1528+
1529+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1530+ def test_cohort_data_with_query (fixture , api ):
1531+ df_all = api .cohorts ("admin1_month" )
1532+ df_filtered = api .cohorts ("admin1_month" , query = "country == 'Burkina Faso'" )
1533+ assert len (df_filtered ) > 0
1534+ assert (df_filtered ["country" ] == "Burkina Faso" ).all ()
1535+ assert len (df_filtered ) < len (df_all )
1536+
1537+
1538+ @parametrize_with_cases ("fixture,api" , cases = case_ag3_sim )
1539+ def test_cohort_data_cached (fixture , api ):
1540+ df1 = api .cohorts ("admin1_month" )
1541+ df2 = api .cohorts ("admin1_month" )
1542+ assert_frame_equal (df1 , df2 )
1543+
1544+
14701545# ------------------------------------------------------------------
14711546# Tests for cohort_geometries()
14721547# ------------------------------------------------------------------
0 commit comments