Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lpicci96 committed Jul 20, 2023
1 parent 06a5057 commit 436ae1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

[1.2.0] - 2023-07-20
--------------------
- Added new feature: `world_bank_projects` module in `import_tools` with an object
to extract data from the World Bank Projects database.

[1.1.1] - 2023-07-06
--------------------
- Updated requirements
Expand Down
23 changes: 13 additions & 10 deletions bblocks/import_tools/world_bank_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ def _format_theme_data(self) -> None:
for _, proj_data in self._raw_data.items():
theme_data.extend(clean_theme(proj_data))

self._data["theme_data"] = pd.DataFrame(theme_data)
self._data["theme_data"] = pd.DataFrame(theme_data).filter(
["project ID", "theme1", "theme2", "theme3", "theme4", "theme5", "percent"],
axis=1,
)

def _format_sector_data(self) -> None:
"""Format sector data and store it as a dataframe in _data attribute
Expand Down Expand Up @@ -459,6 +462,15 @@ def load_data(self, *, additional_fields: str | list = None) -> ImportData:
object with loaded data
"""

# if additional fields are set but the data is read from disk, log a warning
if self._path.exists() and additional_fields is not None:
logger.warning(
"Data already exists in disk. The additional fields might not be "
"loaded if they do not exist in the downloaded data. To force download "
"of data with additional fields, use the update_data method passing the "
"additional fields as argument"
)

# check if additional fields is a string or None and convert to list
if additional_fields is None:
additional_fields = []
Expand All @@ -469,15 +481,6 @@ def load_data(self, *, additional_fields: str | list = None) -> ImportData:
if not self._path.exists():
self._download(additional_fields=additional_fields)

# if file exists and additional fields are passed, log warning
else:
if not additional_fields:
logger.warning(
"Data already exists in disk. The additional fields may not be "
"loaded. To force download of data with additional fields, use the"
" update_data method passing the additional fields as argument"
)

# load data from json file
with open(self._path, "r") as file:
self._raw_data = json.load(file)
Expand Down

0 comments on commit 436ae1f

Please sign in to comment.