Skip to content

Commit

Permalink
-adjust save_forecast function to reflect new code
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-harder committed Nov 22, 2024
1 parent 79dd828 commit efbaa8f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions assume/common/forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(
powerplants_units: pd.DataFrame,
demand_units: pd.DataFrame,
market_configs: dict = {},
save_path: str = "",
*args,
**kwargs,
):
Expand All @@ -122,6 +123,7 @@ def __init__(
self.demand_units = demand_units
self.market_configs = market_configs
self.forecasts = pd.DataFrame(index=index)
self.save_path = save_path

def __getitem__(self, column: str) -> FastSeries:
"""
Expand Down Expand Up @@ -373,7 +375,7 @@ def calculate_marginal_cost(self, pp_series: pd.Series) -> pd.Series:

return marginal_cost

def save_forecasts(self, path):
def save_forecasts(self, path=None):
"""
Saves the forecasts to a csv file located at the specified path.
Expand All @@ -384,12 +386,13 @@ def save_forecasts(self, path):
ValueError: If no forecasts are provided, an error message is logged.
"""

try:
self.forecasts.to_csv(f"{path}/forecasts_df.csv", index=True)
except ValueError:
self.logger.error(
f"No forecasts for {self.market_id} provided, so none saved."
)
path = path or self.save_path

Check warning on line 389 in assume/common/forecasts.py

View check run for this annotation

Codecov / codecov/patch

assume/common/forecasts.py#L389

Added line #L389 was not covered by tests

merged_forecasts = pd.DataFrame(self.forecasts)
merged_forecasts.index = pd.date_range(

Check warning on line 392 in assume/common/forecasts.py

View check run for this annotation

Codecov / codecov/patch

assume/common/forecasts.py#L391-L392

Added lines #L391 - L392 were not covered by tests
start=self.index[0], end=self.index[-1], freq=self.index.freq
)
merged_forecasts.to_csv(f"{path}/forecasts_df.csv", index=True)

Check warning on line 395 in assume/common/forecasts.py

View check run for this annotation

Codecov / codecov/patch

assume/common/forecasts.py#L395

Added line #L395 was not covered by tests

def convert_forecasts_to_fast_series(self):
"""
Expand Down

0 comments on commit efbaa8f

Please sign in to comment.