Skip to content

Commit

Permalink
Fix string formatting operations in unit conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannis-vm committed May 27, 2024
1 parent fb856af commit c92d253
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pelicun/model/loss_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def _aggregate_sample(self, sample, columns):

for decision_variable in self.decision_variables:

# Time ..
# Time
if decision_variable == 'Time' and 'Time' in aggregated.columns:
df_agg['repair_time-sequential'] = aggregated['Time'].sum(axis=1)

Expand All @@ -784,7 +784,7 @@ def _aggregate_sample(self, sample, columns):
df_agg = df_agg.drop(
['repair_time-parallel', 'repair_time-sequential'], axis=1
)
# All other ..
# All other
elif decision_variable in aggregated.columns:
df_agg[f'repair_{decision_variable.lower()}'] = aggregated[
decision_variable
Expand All @@ -808,8 +808,12 @@ def _aggregate_sample(self, sample, columns):
.to_dict()
)

# Convert units ..
column_measures = [
x.replace('repair_', '') for x in df_agg.columns.get_level_values(0)
x.replace('repair_', '')
.replace('-sequential', '')
.replace('-parallel', '')
for x in df_agg.columns.get_level_values(0)
]
column_units = [cmp_units[x.title()] for x in column_measures]
dv_units = pd.Series(column_units, index=df_agg.columns, name='Units')
Expand All @@ -823,6 +827,7 @@ def _aggregate_sample(self, sample, columns):
)
df_agg.drop("Units", inplace=True)
df_agg = df_agg.astype(float)
# ouch..

df_agg = base.convert_to_MultiIndex(df_agg, axis=1)
df_agg.sort_index(axis=1, inplace=True)
Expand Down

0 comments on commit c92d253

Please sign in to comment.