-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fasttrack: fasttrack/latest/foreign_aid_govt_private.csv
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
etl/steps/data/grapher/fasttrack/latest/foreign_aid_govt_private.meta.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
dataset: | ||
title: Foreign aid by governments and private donors | ||
description: '' | ||
licenses: | ||
- {} | ||
tables: | ||
foreign_aid_govt_private: | ||
variables: | ||
foreign_aid_given: | ||
title: Foreign aid given | ||
unit: $ | ||
short_unit: $ | ||
country_or_private: | ||
title: country_or_private | ||
unit: '' |
40 changes: 40 additions & 0 deletions
40
etl/steps/data/grapher/fasttrack/latest/foreign_aid_govt_private.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pandas as pd | ||
|
||
from etl.helpers import PathFinder, create_dataset, get_metadata_path | ||
from etl.snapshot import Snapshot | ||
|
||
paths = PathFinder(__file__) | ||
|
||
|
||
def run(dest_dir: str) -> None: | ||
# load snapshot | ||
snap = Snapshot("fasttrack/latest/foreign_aid_govt_private.csv") | ||
|
||
# load data | ||
tb = snap.read_csv() | ||
|
||
# add dimensions with dim_ prefix | ||
dims = [c for c in tb.columns if c.startswith("dim_")] | ||
dims_without_prefix = [c[4:] for c in dims] | ||
|
||
if dims: | ||
tb = tb.rename(columns={d: dw for d, dw in zip(dims, dims_without_prefix)}) | ||
|
||
if uses_dates(tb["year"]): | ||
tb = tb.rename(columns={"year": "date"}).format(["country", "date"] + dims_without_prefix) | ||
else: | ||
tb = tb.format(["country", "year"] + dims_without_prefix) | ||
|
||
# add table, update metadata from *.meta.yml and save | ||
ds = create_dataset(dest_dir, tables=[tb], default_metadata=snap.metadata) | ||
|
||
# override metadata if necessary | ||
meta_path = get_metadata_path(dest_dir).with_suffix(".override.yml") | ||
if meta_path.exists(): | ||
ds.update_metadata(meta_path) | ||
|
||
ds.save() | ||
|
||
|
||
def uses_dates(s: pd.Series) -> bool: | ||
return pd.to_datetime(s, errors="coerce", format="%Y-%m-%d").notnull().all() |
14 changes: 14 additions & 0 deletions
14
snapshots/fasttrack/latest/foreign_aid_govt_private.csv.dvc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
meta: | ||
origin: | ||
producer: OECD | ||
title: foreign_aid_govt_private | ||
url_download: |- | ||
https://docs.google.com/spreadsheets/d/e/2PACX-1vTS8P48gCF-EVE-VPaFZGc-_M0l1SWiiFaBVMim_37CdES3vMAacU6oppFJ2cKJuKqYyncxE6tLpRsk/pub?output=csv | ||
date_accessed: '2025-02-05' | ||
name: Foreign aid by governments and private donors | ||
description: '' | ||
license: {} | ||
outs: | ||
- md5: 1973e716bf34b2d8c58ce83b045a5335 | ||
size: 3315 | ||
path: foreign_aid_govt_private.csv |