Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multidimension variable load #3520

Closed
wants to merge 9 commits into from
8 changes: 8 additions & 0 deletions dag/archive/poverty_inequality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ steps:
- data://garden/wb/2024-03-27/world_bank_pip
data://grapher/wb/2024-03-27/world_bank_pip_2017ppp:
- data://garden/wb/2024-03-27/world_bank_pip

# Multidimensional Poverty Index
data://meadow/ophi/2023-07-05/multidimensional_poverty_index:
- snapshot://ophi/2023-07-05/multidimensional_poverty_index.csv
data://garden/ophi/2023-07-05/multidimensional_poverty_index:
- data://meadow/ophi/2023-07-05/multidimensional_poverty_index
data://grapher/ophi/2023-07-05/multidimensional_poverty_index:
- data://garden/ophi/2023-07-05/multidimensional_poverty_index
15 changes: 8 additions & 7 deletions dag/poverty_inequality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ steps:
data://explorers/lis/latest/luxembourg_income_study:
- data://garden/lis/2024-06-13/luxembourg_income_study

# Multidimensional Poverty Index
data://meadow/ophi/2023-07-05/multidimensional_poverty_index:
- snapshot://ophi/2023-07-05/multidimensional_poverty_index.csv
data://garden/ophi/2023-07-05/multidimensional_poverty_index:
- data://meadow/ophi/2023-07-05/multidimensional_poverty_index
data://grapher/ophi/2023-07-05/multidimensional_poverty_index:
- data://garden/ophi/2023-07-05/multidimensional_poverty_index
# Global Multidimensional Poverty Index
data://meadow/ophi/2024-10-28/multidimensional_poverty_index:
- snapshot://ophi/2024-10-28/multidimensional_poverty_index_cme.csv
- snapshot://ophi/2024-10-28/multidimensional_poverty_index_hot.csv
data://garden/ophi/2024-10-28/multidimensional_poverty_index:
- data://meadow/ophi/2024-10-28/multidimensional_poverty_index
data://grapher/ophi/2024-10-28/multidimensional_poverty_index:
- data://garden/ophi/2024-10-28/multidimensional_poverty_index

# # OECD Income Distribution Database
data://meadow/oecd/2024-04-10/income_distribution_database:
Expand Down
26 changes: 19 additions & 7 deletions etl/grapher_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,19 +510,31 @@ def variable_data_table_from_catalog(
# {'name': 'gender', 'value': 'all'},
# {'name': 'age_group', 'value': '15-29'}
# ]
filters = variables[0].dimensions["filters"]
dim_names = [f["name"] for f in filters]
# Collect unique dimension names across all variables' filters.
dim_names = []
for variable in variables:
if "filters" in variable.dimensions: # type: ignore
for f in variable.dimensions["filters"]: # type: ignore
if f["name"] not in dim_names:
dim_names.append(f["name"])

# Pivot the table using the generalized dimension names.
tb_pivoted = tb.pivot(index=["country", "year"], columns=dim_names)

# Generate labels with exact structure matching tb_pivoted.columns.
labels = []
for variable in variables:
assert variable.dimensions, f"Variable {variable.id} has no dimensions"
labels.append(
tuple(
[variable.dimensions["originalShortName"]]
+ [f["value"] for f in variable.dimensions["filters"]]
label_tuple = [variable.dimensions["originalShortName"]]

# Add filter values in the same order as dim_names.
for name in dim_names:
value = next(
(f["value"] for f in variable.dimensions.get("filters", []) if f["name"] == name), None
)
)
label_tuple.append(value) # type: ignore

labels.append(tuple(label_tuple))

tb = tb_pivoted.loc[:, labels]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"Afghanistan": "Afghanistan",
"Albania": "Albania",
"Algeria": "Algeria",
"Armenia": "Armenia",
"Bangladesh": "Bangladesh",
"Belize": "Belize",
"Benin": "Benin",
"Bolivia": "Bolivia",
"Bosnia and Herzegovina": "Bosnia and Herzegovina",
"Burkina Faso": "Burkina Faso",
"Burundi": "Burundi",
"Cambodia": "Cambodia",
"Cameroon": "Cameroon",
"Central African Republic": "Central African Republic",
"Chad": "Chad",
"China": "China",
"Colombia": "Colombia",
"Comoros": "Comoros",
"Congo": "Congo",
"Cote d'Ivoire": "Cote d'Ivoire",
"Dominican Republic": "Dominican Republic",
"Ecuador": "Ecuador",
"Egypt": "Egypt",
"Eswatini": "Eswatini",
"Ethiopia": "Ethiopia",
"Gabon": "Gabon",
"Gambia": "Gambia",
"Ghana": "Ghana",
"Guinea": "Guinea",
"Guinea-Bissau": "Guinea-Bissau",
"Guyana": "Guyana",
"Haiti": "Haiti",
"Honduras": "Honduras",
"India": "India",
"Indonesia": "Indonesia",
"Iraq": "Iraq",
"Jamaica": "Jamaica",
"Jordan": "Jordan",
"Kazakhstan": "Kazakhstan",
"Kenya": "Kenya",
"Kyrgyzstan": "Kyrgyzstan",
"Lao PDR": "Laos",
"Lesotho": "Lesotho",
"Liberia": "Liberia",
"Madagascar": "Madagascar",
"Malawi": "Malawi",
"Mali": "Mali",
"Mauritania": "Mauritania",
"Mexico": "Mexico",
"Moldova": "Moldova",
"Mongolia": "Mongolia",
"Montenegro": "Montenegro",
"Morocco": "Morocco",
"Mozambique": "Mozambique",
"Namibia": "Namibia",
"Nepal": "Nepal",
"Nicaragua": "Nicaragua",
"Niger": "Niger",
"Nigeria": "Nigeria",
"North Macedonia": "North Macedonia",
"Pakistan": "Pakistan",
"Palestine, State of": "Palestine",
"Peru": "Peru",
"Philippines": "Philippines",
"Rwanda": "Rwanda",
"Sao Tome and Principe": "Sao Tome and Principe",
"Senegal": "Senegal",
"Serbia": "Serbia",
"Sierra Leone": "Sierra Leone",
"Sudan": "Sudan",
"Suriname": "Suriname",
"Tajikistan": "Tajikistan",
"Tanzania": "Tanzania",
"Thailand": "Thailand",
"Timor-Leste": "East Timor",
"Togo": "Togo",
"Trinidad and Tobago": "Trinidad and Tobago",
"Tunisia": "Tunisia",
"Turkmenistan": "Turkmenistan",
"Uganda": "Uganda",
"Ukraine": "Ukraine",
"Viet Nam": "Vietnam",
"Yemen": "Yemen",
"Zambia": "Zambia",
"Zimbabwe": "Zimbabwe",
"Congo, Democratic Republic of the": "Democratic Republic of Congo",
"Angola": "Angola",
"Argentina": "Argentina",
"Barbados": "Barbados",
"Bhutan": "Bhutan",
"Botswana": "Botswana",
"Brazil": "Brazil",
"Costa Rica": "Costa Rica",
"Cuba": "Cuba",
"El Salvador": "El Salvador",
"Fiji": "Fiji",
"Georgia": "Georgia",
"Guatemala": "Guatemala",
"Kiribati": "Kiribati",
"Libya": "Libya",
"Maldives": "Maldives",
"Myanmar": "Myanmar",
"Papua New Guinea": "Papua New Guinea",
"Paraguay": "Paraguay",
"Saint Lucia": "Saint Lucia",
"Samoa": "Samoa",
"Seychelles": "Seychelles",
"South Africa": "South Africa",
"Sri Lanka": "Sri Lanka",
"Tonga": "Tonga",
"Tuvalu": "Tuvalu",
"Uzbekistan": "Uzbekistan"
}
Loading
Loading