Skip to content

Commit

Permalink
fasttrack: fasttrack/latest/foreign_aid_govt_private.csv
Browse files Browse the repository at this point in the history
  • Loading branch information
owidbot committed Feb 5, 2025
1 parent ea05442 commit 0b193a7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dag/fasttrack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,5 @@ steps:
- snapshot://fasttrack/latest/in_donor_foreign_aid_categories_dac_countries.csv
data://grapher/fasttrack/latest/poverty_latam_idb:
- snapshot://fasttrack/latest/poverty_latam_idb.csv
data://grapher/fasttrack/latest/foreign_aid_govt_private:
- snapshot://fasttrack/latest/foreign_aid_govt_private.csv
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: ''
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 snapshots/fasttrack/latest/foreign_aid_govt_private.csv.dvc
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

0 comments on commit 0b193a7

Please sign in to comment.