-
-
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/_2__2023_in_donor_individual_countries__s…
…heet1.csv
- Loading branch information
Showing
4 changed files
with
85 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
27 changes: 27 additions & 0 deletions
27
...eps/data/grapher/fasttrack/latest/_2__2023_in_donor_individual_countries__sheet1.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,27 @@ | ||
dataset: | ||
title: DRAFT 2 – 2023 In-donor individual countries - Sheet1 | ||
description: '' | ||
tables: | ||
_2__2023_in_donor_individual_countries__sheet1: | ||
variables: | ||
debt_relief: | ||
title: Debt_Relief | ||
unit: '' | ||
in_donor_student_costs: | ||
title: In_Donor_Student_Costs | ||
unit: '' | ||
in_donor_refugee_costs: | ||
title: In_Donor_Refugee_Costs | ||
unit: '' | ||
development_awareness: | ||
title: Development_Awareness | ||
unit: '' | ||
administrative_costs: | ||
title: Administrative_Costs | ||
unit: '' | ||
in_donor_research: | ||
title: In_Donor_Research | ||
unit: '' | ||
total: | ||
title: Total | ||
unit: '' |
40 changes: 40 additions & 0 deletions
40
etl/steps/data/grapher/fasttrack/latest/_2__2023_in_donor_individual_countries__sheet1.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/_2__2023_in_donor_individual_countries__sheet1.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() |
16 changes: 16 additions & 0 deletions
16
snapshots/fasttrack/latest/_2__2023_in_donor_individual_countries__sheet1.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,16 @@ | ||
meta: | ||
origin: | ||
producer: Unknown | ||
title: Unknown | ||
citation_full: Unknown | ||
version_producer: Local CSV | ||
url_main: https://unknown.com | ||
url_download: 2 – 2023 In-donor individual countries - Sheet1.csv | ||
date_accessed: '2025-01-30' | ||
date_published: '2025-01-30' | ||
name: DRAFT 2 – 2023 In-donor individual countries - Sheet1 | ||
description: '' | ||
outs: | ||
- md5: 0594ff5700e3df26d0420767f1d08a70 | ||
size: 1115 | ||
path: _2__2023_in_donor_individual_countries__sheet1.csv |