Skip to content

Commit

Permalink
Batchrunner: Remove unnecessary dict transformation, keys() in len()
Browse files Browse the repository at this point in the history
- Removes one unnecessary dict transformation
- Removes three unnecessary calls of .keys() when getting the dict lenght
  • Loading branch information
EwoutH committed Oct 30, 2022
1 parent af23b8b commit 6e60a83
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mesa/batchrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __init__(
parameters_list = []
self.parameters_list = list(parameters_list)
self.fixed_parameters = fixed_parameters or {}
self._include_fixed = len(self.fixed_parameters.keys()) > 0
self._include_fixed = len(self.fixed_parameters) > 0
self.iterations = iterations
self.max_steps = max_steps

Expand Down Expand Up @@ -472,8 +472,7 @@ def _prepare_report_table(self, vars_dict, extra_cols=None):
ordered = df[index_cols + list(sorted(rest_cols))]
ordered.sort_values(by="Run", inplace=True)
if self._include_fixed:
for param in self.fixed_parameters.keys():
val = self.fixed_parameters[param]
for param, val in self.fixed_parameters.items():

# avoid error when val is an iterable
vallist = [val for i in range(ordered.shape[0])]
Expand Down Expand Up @@ -733,9 +732,9 @@ def _result_prep_mp(self, results):
] = model.datacollector.get_agent_vars_dataframe()

# Make results consistent
if len(self.datacollector_model_reporters.keys()) == 0:
if len(self.datacollector_model_reporters) == 0:
self.datacollector_model_reporters = None
if len(self.datacollector_agent_reporters.keys()) == 0:
if len(self.datacollector_agent_reporters) == 0:
self.datacollector_agent_reporters = None

def run_all(self):
Expand Down

0 comments on commit 6e60a83

Please sign in to comment.