Skip to content

Commit

Permalink
[Fix] Change iterrows to itertuples to preserve datatypes in numeric …
Browse files Browse the repository at this point in the history
…dataframes
  • Loading branch information
ephoris committed Feb 5, 2024
1 parent 71afa15 commit 9f129a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions mlos_core/mlos_core/optimizers/flaml_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ def _register(self, configurations: pd.DataFrame, scores: pd.Series,
"""
if context is not None:
raise NotImplementedError()
for (_, config), score in zip(configurations.iterrows(), scores):
for config, score in zip(configurations.itertuples(index=False), scores):
config = config._asdict()
cs_config: ConfigSpace.Configuration = ConfigSpace.Configuration(
self.optimizer_parameter_space, values=config.to_dict())
self.optimizer_parameter_space, values=config)
if cs_config in self.evaluated_samples:
warn(f"Configuration {config} was already registered", UserWarning)

self.evaluated_samples[cs_config] = EvaluatedSample(config=config.to_dict(), score=score)
self.evaluated_samples[cs_config] = EvaluatedSample(config=config, score=score)

def _suggest(self, context: Optional[pd.DataFrame] = None) -> pd.DataFrame:
"""Suggests a new configuration.
Expand Down
5 changes: 3 additions & 2 deletions mlos_core/mlos_core/spaces/adapters/llamatune.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def target_parameter_space(self) -> ConfigSpace.ConfigurationSpace:

def inverse_transform(self, configurations: pd.DataFrame) -> pd.DataFrame:
target_configurations = []
for (_, config) in configurations.iterrows():
configuration = ConfigSpace.Configuration(self.orig_parameter_space, values=config.to_dict())
for config in configurations.itertuples(index=False):
config = config._asdict()
configuration = ConfigSpace.Configuration(self.orig_parameter_space, values=config)

target_config = self._suggested_configs.get(configuration, None)
# NOTE: HeSBO is a non-linear projection method, and does not inherently support inverse projection
Expand Down

0 comments on commit 9f129a5

Please sign in to comment.