Skip to content

Commit

Permalink
Merge pull request #26 from paul-florentin-charles/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
paul-florentin-charles authored Sep 25, 2023
2 parents 03e8e33 + 04ccbc9 commit ccb13ef
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coveragepy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/pytest.yml

This file was deleted.

4 changes: 1 addition & 3 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from yaml import safe_load

CONFIG_FNAME: str = 'config.yaml'
UTF_8: str = 'utf-8'
MODE: str = 'rt'


class Config:
Expand All @@ -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:
Expand Down
15 changes: 9 additions & 6 deletions src/core/models/all_rainfall.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""
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

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
Expand All @@ -20,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,
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/core/models/monthly_rainfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/core/models/seasonal_rainfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
8 changes: 4 additions & 4 deletions src/core/models/yearly_rainfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tst/functions/test_dataframe_operations.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ccb13ef

Please sign in to comment.