Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate to poetry for package setup and dependencies management #31

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,345 changes: 2,345 additions & 0 deletions data-preparation/poetry.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions data-preparation/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "sdp-data-preparation"
version = "0.1.0"
description = "All the steps of the data preparation for the Shift Data Portal: extraction, transformation and loading."
authors = ["Sébastien Bourgeois <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
pandas = "^2.2.1"
requests = "^2.31.0"

[tool.poetry.group.dev.dependencies]
jupyter = "^1.0.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
154 changes: 0 additions & 154 deletions data-preparation/requirements.txt

This file was deleted.

Empty file.
6 changes: 0 additions & 6 deletions data-preparation/setup.cfg

This file was deleted.

3 changes: 0 additions & 3 deletions data-preparation/setup.py

This file was deleted.

10 changes: 6 additions & 4 deletions data-preparation/src/main_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import os
import requests
from pandas import json_normalize
from utils import get_project_root_path

RAW_DATA_DIR = "../../data/raw_data" # contains the RAW data sources (have to be downloaded from Internet and placed in this folder)
RESULTS_DIR = "../../data/new_prod_data"
CURRENT_DATA_DIR = "../../data/current_data"
CURRENT_PROD_DATA = "../../data/current_prod_data" # contains TRANSFORMED old data generated by Dataiku.
PROJECT_ROOT_DIR = get_project_root_path()
RAW_DATA_DIR = os.path.join(PROJECT_ROOT_DIR, "/data/raw_data") # contains the RAW data sources (have to be downloaded from Internet and placed in this folder)
RESULTS_DIR = os.path.join(PROJECT_ROOT_DIR, "/data/new_prod_data")
CURRENT_DATA_DIR = os.path.join(PROJECT_ROOT_DIR, "/data/current_data")
CURRENT_PROD_DATA = os.path.join(PROJECT_ROOT_DIR, "/data/current_prod_data") # contains TRANSFORMED old data generated by Dataiku.


class TransformationPipeline:
Expand Down
5 changes: 2 additions & 3 deletions data-preparation/src/transformation/fossil_import_export.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pandas as pd
import numpy as np
import sys

sys.path.insert(0, r'C:\Users\HP\Desktop\shiftdataportal_data')
from src.sdp_data.utils.translation import CountryTranslatorFrenchToEnglish
from src.sdp_data.utils.utils import diff_evaluation
from utils.translation import CountryTranslatorFrenchToEnglish
from utils.utils import diff_evaluation


# Class to update recent data
Expand Down
2 changes: 1 addition & 1 deletion data-preparation/src/transformation/fossil_reserves.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import sys
sys.path.insert(0, r'C:\Users\HP\Desktop\shiftdataportal_data')
from src.sdp_data.utils.translation import CountryTranslatorFrenchToEnglish
from utils.translation import CountryTranslatorFrenchToEnglish


class CoalReservesConsolidatedProdGenerator:
Expand Down
2 changes: 1 addition & 1 deletion data-preparation/src/transformation/historical_co2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd
from utils.translation import CountryTranslatorFrenchToEnglish
from sdp_data.transformation.demographic.countries import StatisticsPerCountriesAndZonesJoiner
from demographic.countries import StatisticsPerCountriesAndZonesJoiner


class HistoricalCo2PerZoneAndCountryProcessor:
Expand Down
2 changes: 1 addition & 1 deletion data-preparation/src/transformation/iea.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from utils.iso3166 import countries
from utils.translation import CountryTranslatorFrenchToEnglish
from sdp_data.transformation.demographic.countries import StatisticsPerCountriesAndZonesJoiner
from demographic.countries import StatisticsPerCountriesAndZonesJoiner
from utils.format import StatisticsDataframeFormatter
import requests
import json
Expand Down
1 change: 1 addition & 0 deletions data-preparation/src/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .utils import get_project_root_path
14 changes: 14 additions & 0 deletions data-preparation/src/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from utils.translation import CountryTranslatorFrenchToEnglish
import pandas as pd

Expand Down Expand Up @@ -118,3 +120,15 @@ def check_columns_diff(res_old, res_new, country_col):
return country_old, country_new


def get_project_root_path() -> str:
"""Returns the path of the project root"""
dir_path = os.path.dirname(os.path.realpath(__file__))
dir_name = os.path.basename(dir_path)

# We go up in the directory level until
# we are at the root of the project
while dir_name != "shiftdataportal":
dir_path = os.path.dirname(dir_path)
dir_name = os.path.basename(dir_path)

return dir_path