Skip to content

Commit

Permalink
chore: apply Black and Ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth7113 committed Dec 7, 2024
1 parent 4b9aaa7 commit 46d31aa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
10 changes: 3 additions & 7 deletions neso_solar_consumer/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import pandas as pd


def fetch_data(
resource_id: str, limit: int, columns: list, rename_columns: dict
) -> pd.DataFrame:
def fetch_data(resource_id: str, limit: int, columns: list, rename_columns: dict) -> pd.DataFrame:
"""
Fetch data from the NESO API and process it into a Pandas DataFrame.
Expand Down Expand Up @@ -55,9 +53,7 @@ def fetch_data(
return pd.DataFrame()


def fetch_data_using_sql(
sql_query: str, columns: list, rename_columns: dict
) -> pd.DataFrame:
def fetch_data_using_sql(sql_query: str, columns: list, rename_columns: dict) -> pd.DataFrame:
"""
Fetch data from the NESO API using an SQL query, process it, and return specific columns with renamed headers.
Expand Down Expand Up @@ -98,4 +94,4 @@ def fetch_data_using_sql(

except Exception as e:
print(f"An error occurred: {e}")
return pd.DataFrame()
return pd.DataFrame()
2 changes: 1 addition & 1 deletion neso_solar_consumer/format_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def format_to_forecast_sql(data: pd.DataFrame, model_tag: str, model_version: st
forecast_values = [
ForecastValue(
target_time=target_time,
expected_power_generation_megawatts=row["solar_forecast_kw"]
expected_power_generation_megawatts=row["solar_forecast_kw"],
).to_orm()
]

Expand Down
1 change: 1 addition & 0 deletions neso_solar_consumer/save_forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from nowcasting_datamodel.save.save import save


def save_forecasts_to_db(forecasts: list, session):
"""
Save a list of ForecastSQL objects to the database using the nowcasting_datamodel `save` function.
Expand Down
6 changes: 2 additions & 4 deletions tests/test_fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""

import pytest
import pytest # noqa: F401
from neso_solar_consumer.fetch_data import fetch_data, fetch_data_using_sql


Expand Down Expand Up @@ -69,6 +69,4 @@ def test_data_consistency():
"""
df_api = fetch_data(resource_id, limit, columns, rename_columns)
df_sql = fetch_data_using_sql(sql_query, columns, rename_columns)
assert df_api.equals(
df_sql
), "Data from fetch_data and fetch_data_using_sql are inconsistent!"
assert df_api.equals(df_sql), "Data from fetch_data and fetch_data_using_sql are inconsistent!"
2 changes: 2 additions & 0 deletions tests/test_save_forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
MODEL_NAME = "real_data_model"
MODEL_VERSION = "1.0"


@pytest.fixture
def db_session():
"""
Expand All @@ -44,6 +45,7 @@ def db_session():
session.close()
engine.dispose()


def test_save_real_forecasts(db_session):
"""
Integration test: Fetch real data, format it into forecasts, and save to the database.
Expand Down

0 comments on commit 46d31aa

Please sign in to comment.