From 2aa3bb7dbb773abfbf9e94e492be993342b494b7 Mon Sep 17 00:00:00 2001 From: polochinoc Date: Tue, 19 Sep 2023 22:09:22 +0200 Subject: [PATCH 1/3] Restricted workflows to Python 3.9 and 3.10 --- .github/workflows/coveragepy.yml | 2 +- .github/workflows/pylint.yml | 2 +- .github/workflows/pytest.yml | 2 +- tst/functions/test_dataframe_operations.py | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coveragepy.yml b/.github/workflows/coveragepy.yml index eb8dc72..5dcb7be 100644 --- a/.github/workflows/coveragepy.yml +++ b/.github/workflows/coveragepy.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.9", "3.10"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 93a8906..403fcd8 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.9", "3.10"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index a0ad089..6a543ee 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.9", "3.10"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/tst/functions/test_dataframe_operations.py b/tst/functions/test_dataframe_operations.py index 11bb0ff..283a9c1 100644 --- a/tst/functions/test_dataframe_operations.py +++ b/tst/functions/test_dataframe_operations.py @@ -1,6 +1,7 @@ # pylint: disable=missing-docstring from datetime import datetime + import pandas as pd import src.core.utils.functions.dataframe_operations as df_opr From 87f9864ca18a0f2ba7b57b9941ba6ee2bb22283b Mon Sep 17 00:00:00 2001 From: polochinoc Date: Mon, 25 Sep 2023 21:59:04 +0200 Subject: [PATCH 2/3] Removed redundant Pytest WF | Modified constructors of YearlyRainfall class & subclasses to take directly raw data instead of dataset URL --- .github/workflows/pytest.yml | 24 ------------------------ src/core/models/all_rainfall.py | 9 ++++++--- src/core/models/monthly_rainfall.py | 4 ++-- src/core/models/seasonal_rainfall.py | 4 ++-- src/core/models/yearly_rainfall.py | 6 +++--- 5 files changed, 13 insertions(+), 34 deletions(-) delete mode 100644 .github/workflows/pytest.yml diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml deleted file mode 100644 index 6a543ee..0000000 --- a/.github/workflows/pytest.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Pytest - -on: push - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10"] - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pytest - - name: Running tests with pytest - run: | - pytest tst diff --git a/src/core/models/all_rainfall.py b/src/core/models/all_rainfall.py index f19e9ab..d1eb72e 100644 --- a/src/core/models/all_rainfall.py +++ b/src/core/models/all_rainfall.py @@ -5,6 +5,8 @@ from typing import Optional +import pandas as pd + from src.core.models.monthly_rainfall import MonthlyRainfall from src.core.models.seasonal_rainfall import SeasonalRainfall from src.core.models.yearly_rainfall import YearlyRainfall @@ -30,18 +32,19 @@ def __init__(self, self.dataset_url: str = dataset_url self.starting_year: int = start_year self.round_precision: int = round_precision - self.yearly_rainfall: YearlyRainfall = YearlyRainfall(dataset_url, + self.raw_data: pd.DataFrame = pd.read_csv(dataset_url) + self.yearly_rainfall: YearlyRainfall = YearlyRainfall(self.raw_data, start_year, round_precision) self.monthly_rainfalls: list = [] for month in Month: - self.monthly_rainfalls.append(MonthlyRainfall(dataset_url, + self.monthly_rainfalls.append(MonthlyRainfall(self.raw_data, month, start_year, round_precision)) self.seasonal_rainfalls: list = [] for season in Season: - self.seasonal_rainfalls.append(SeasonalRainfall(dataset_url, + self.seasonal_rainfalls.append(SeasonalRainfall(self.raw_data, season, start_year, round_precision)) diff --git a/src/core/models/monthly_rainfall.py b/src/core/models/monthly_rainfall.py index f08e046..457d92f 100644 --- a/src/core/models/monthly_rainfall.py +++ b/src/core/models/monthly_rainfall.py @@ -16,12 +16,12 @@ class MonthlyRainfall(YearlyRainfall): """ def __init__(self, - dataset_url: str, + raw_data: pd.DataFrame, month: Month, start_year: Optional[int] = 1970, round_precision: Optional[int] = 2): self.month: Month = month - super().__init__(dataset_url, start_year, round_precision) + super().__init__(raw_data, start_year, round_precision) def load_yearly_rainfall(self) -> pd.DataFrame: """ diff --git a/src/core/models/seasonal_rainfall.py b/src/core/models/seasonal_rainfall.py index 140ba24..92aeda2 100644 --- a/src/core/models/seasonal_rainfall.py +++ b/src/core/models/seasonal_rainfall.py @@ -16,12 +16,12 @@ class SeasonalRainfall(YearlyRainfall): """ def __init__(self, - dataset_url: str, + raw_data: pd.DataFrame, season: Season, start_year: Optional[int] = 1970, round_precision: Optional[int] = 2): self.season: Season = season - super().__init__(dataset_url, start_year, round_precision) + super().__init__(raw_data, start_year, round_precision) def load_yearly_rainfall(self) -> pd.DataFrame: """ diff --git a/src/core/models/yearly_rainfall.py b/src/core/models/yearly_rainfall.py index ddb818d..0ef7e82 100644 --- a/src/core/models/yearly_rainfall.py +++ b/src/core/models/yearly_rainfall.py @@ -25,10 +25,10 @@ class YearlyRainfall: """ def __init__(self, - dataset_url: str, + raw_data: pd.DataFrame, start_year: Optional[int] = 1970, round_precision: Optional[int] = 2): - self.dataset_url: str = dataset_url + self.raw_data = raw_data self.starting_year: int = start_year self.round_precision: int = round_precision self.data: pd.DataFrame = self.load_yearly_rainfall() @@ -58,7 +58,7 @@ def load_rainfall(self, :return: A pandas DataFrame displaying rainfall data (in mm) according to year. """ - return df_opr.retrieve_rainfall_data_with_constraints(pd.read_csv(self.dataset_url), + return df_opr.retrieve_rainfall_data_with_constraints(self.raw_data, self.starting_year, self.round_precision, start_month, From 04ccbc946eb3617c9f028f589f0bfa10983dd19e Mon Sep 17 00:00:00 2001 From: polochinoc Date: Mon, 25 Sep 2023 22:45:29 +0200 Subject: [PATCH 3/3] Modified some docstrings | Removed global variables used only once in config.py --- src/config.py | 4 +--- src/core/models/all_rainfall.py | 6 +++--- src/core/models/yearly_rainfall.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/config.py b/src/config.py index 046b01a..76d4b36 100644 --- a/src/config.py +++ b/src/config.py @@ -6,8 +6,6 @@ from yaml import safe_load CONFIG_FNAME: str = 'config.yaml' -UTF_8: str = 'utf-8' -MODE: str = 'rt' class Config: @@ -19,7 +17,7 @@ class Config: def __init__(self, path: Optional[str] = CONFIG_FNAME): self.path: str = path - with open(self.path, mode=MODE, encoding=UTF_8) as stream: + with open(self.path, mode='rt', encoding='utf-8') as stream: self.yaml_config: dict = safe_load(stream) def get_dataset_url(self) -> str: diff --git a/src/core/models/all_rainfall.py b/src/core/models/all_rainfall.py index d1eb72e..44ea668 100644 --- a/src/core/models/all_rainfall.py +++ b/src/core/models/all_rainfall.py @@ -1,6 +1,6 @@ """ -Provides a costly to instantiate all-in-one class -to manipulate rainfall data for every timeframes. +Provides an all-in-one class to manipulate rainfall data for every timeframe. +At a yearly, monthly and seasonal level. """ from typing import Optional @@ -22,7 +22,7 @@ class AllRainfall: - MonthlyRainfall data for all months - SeasonalRainfall data for all seasons - Costly to instantiate but contains all necessary data. + A bit costly to instantiate but contains all necessary data. """ def __init__(self, diff --git a/src/core/models/yearly_rainfall.py b/src/core/models/yearly_rainfall.py index 0ef7e82..55daff8 100644 --- a/src/core/models/yearly_rainfall.py +++ b/src/core/models/yearly_rainfall.py @@ -49,7 +49,7 @@ def load_rainfall(self, start_month: int, end_month: Optional[int] = None) -> pd.DataFrame: """ - Generic function to load Yearly Rainfall data into pandas DataFrame. + Generic function to load Yearly Rainfall data from raw data stored in pandas DataFrame. :param start_month: An integer representing the month to start getting our rainfall values (compulsory)