-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/pdct 1419 map family metadata to metadata key in family json …
…structure (#13) * WIP : implement mapping for family metadata * feat: add helper functions checks if row has any required columns with empty values, checks if required columns from a row are missing * refactor: update helper function to display columns with empty values add tests accordingly * refactor: revert code back to display generic value error message will revisit to try and fix pyright typing errors * feat: update family data mapper - add function to check for value and key existence in nested objects - add private methods - doc string tidy ups - tidy up function that gets budget information * refactor: move function into helper file it can be used more widely across the codebase * refactor: update required columns to be a set instead of a list * test: add test for family mapping * Bump version to 0.1.9 * test: update family test data * test: update conftest fixture to include fields that we interact with * bump version to 0.1.10 * refactor: tidy up mapper to limit value errors being raised instead of raising and stopping the tool from running we can just stdout the error * refactor: update naming to improve readability * refactor: update our checks for false values - remove the function that checks for values in nested objects - we don't want the tool to stop running for malformed data, only when a key is missing. - so we have updated the helper function to check for false/empty values in a list and just echo it out and then take it to the client - We have gone back to pythons normal way of accessing keys in a dict, where a key error will be raised if we try access something that is not there * refactor: renaming of variables and functions to make them a bit more legible * test: update tests * feat: add rquired columns to conftest * refactor: remove duplicate helper function * test: fix failing test, updated error message * chore: add context to why we are returning [0] for budgets --------- Co-authored-by: Osneil Drakes <[email protected]> Co-authored-by: Osneil Drakes <[email protected]>
- Loading branch information
1 parent
57dfbe5
commit 4665dd9
Showing
9 changed files
with
621 additions
and
71 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
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,33 @@ | ||
from enum import Enum | ||
|
||
|
||
class FamilyColumnsNames(Enum): | ||
"""The fields the GCF data mapper needs to parse family data/ metadata.""" | ||
|
||
APPROVED_REF = "ApprovedRef" | ||
COUNTRIES = "Countries" | ||
ENTITIES = "Entities" | ||
FUNDING = "Funding" | ||
PROJECT_URL = "ProjectURL" | ||
PROJECTS_ID = "ProjectsID" | ||
RESULT_AREAS = "ResultAreas" | ||
SECTOR = "Sector" | ||
THEME = "Theme" | ||
|
||
|
||
class FamilyNestedColumnNames(Enum): | ||
"""The fields the GCF data mapper needs to parse nested family data/ metadata.""" | ||
|
||
AREA = "Area" | ||
BUDGET = "BudgetUSDeq" | ||
NAME = "Name" | ||
REGION = "Region" | ||
SOURCE = "Source" | ||
TYPE = "Type" | ||
|
||
|
||
class GCFProjectBudgetSource(Enum): | ||
"""The source of financing for the project's budget funding""" | ||
|
||
CO_FINANCING = "Co-Financing" | ||
GCF = "GCF" |
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "gcf-data-mapper" | ||
version = "0.1.9" | ||
version = "0.1.10" | ||
description = "A CLI tool to wrangle GCF data into format recognised by the bulk-import tool." | ||
authors = ["CPR-dev-team <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
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,61 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from gcf_data_mapper.enums.family import FamilyColumnsNames, FamilyNestedColumnNames | ||
|
||
|
||
@pytest.fixture() | ||
def test_family_doc_df(): | ||
yield pd.DataFrame( | ||
[ | ||
{ | ||
"ProjectsID": 12660, | ||
"ApprovedRef": "FP003", | ||
"ProjectName": "Enhancing resilience of coastal ecosystems and communities", | ||
"Theme": "Adaptation", | ||
"Sector": "Environment", | ||
"ProjectURL": "https://www.climateaction.fund/project/FP003", | ||
"Countries": [ | ||
{ | ||
"CountryName": "Bangladesh", | ||
"ISO3": "BGD", | ||
"Region": "Asia", | ||
}, | ||
], | ||
"Entities": [ | ||
{ | ||
"Name": "Green Innovations", | ||
} | ||
], | ||
"Funding": [ | ||
{ | ||
"Source": "GCF", | ||
"Budget": 9200000, | ||
"BudgetUSDeq": 9200000, | ||
}, | ||
{ | ||
"ProjectBudgetID": 412, | ||
"Source": "Co-Financing", | ||
"Budget": 620000, | ||
"BudgetUSDeq": 620000, | ||
}, | ||
], | ||
"ResultAreas": [ | ||
{ | ||
"Area": "Coastal protection and restoration", | ||
"Type": "Adaptation", | ||
}, | ||
], | ||
} | ||
] | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def required_family_columns(): | ||
required_columns = [column.value for column in FamilyColumnsNames] | ||
required_nested_family_columns = [ | ||
column.value for column in FamilyNestedColumnNames | ||
] | ||
|
||
return required_columns, required_nested_family_columns |
Oops, something went wrong.