Skip to content

Commit

Permalink
Address some pandas FuturesWarnings (#653)
Browse files Browse the repository at this point in the history
Polish for a demo.

See Also: https://stackoverflow.com/a/61185987

---------

Co-authored-by: Sergiy Matusevych <sergiym@microsoft.com>
  • Loading branch information
bpkroth and motus authored Jan 27, 2024
1 parent d073fc1 commit 3a36797
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mlos_bench/mlos_bench/environments/local/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def run(self) -> Tuple[Status, Optional[Dict[str, TunableValue]]]:
_LOG.info("Local results have (metric,value) header and %d rows: assume long format", len(data))
data = pandas.DataFrame([data.value.to_list()], columns=data.metric.to_list())
# Try to convert string metrics to numbers.
data = data.apply(pandas.to_numeric, errors="ignore") # type: ignore[assignment] # (false positive)
data = data.apply(pandas.to_numeric, errors='coerce').fillna(data) # type: ignore[assignment] # (false positive)
elif len(data) == 1:
_LOG.info("Local results have 1 row: assume wide format")
else:
Expand Down
2 changes: 1 addition & 1 deletion mlos_bench/mlos_bench/optimizers/mlos_core_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _to_df(self, configs: Sequence[Dict[str, TunableValue]]) -> pd.DataFrame:
if tunable.name in missing_cols:
df_configs[tunable.name] = tunable.default
else:
df_configs[tunable.name].fillna(tunable.default, inplace=True)
df_configs.fillna({tunable.name: tunable.default}, inplace=True)
# External data can have incorrect types (e.g., all strings).
df_configs[tunable.name] = df_configs[tunable.name].astype(tunable.dtype)
# Add columns for tunables with special values.
Expand Down
6 changes: 4 additions & 2 deletions mlos_bench/mlos_bench/storage/sql/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def get_results_df(
columns=['trial_id', 'tunable_config_id', 'param', 'value']
).pivot(
index=["trial_id", "tunable_config_id"], columns="param", values="value",
).apply(pandas.to_numeric, errors='ignore')
)
configs_df = configs_df.apply(pandas.to_numeric, errors='coerce').fillna(configs_df) # type: ignore[assignment] # (fp)

# Get each trial's results in wide format.
results_stmt = schema.trial_result.select().with_only_columns(
Expand All @@ -164,7 +165,8 @@ def get_results_df(
columns=['trial_id', 'metric', 'value']
).pivot(
index="trial_id", columns="metric", values="value",
).apply(pandas.to_numeric, errors='ignore')
)
results_df = results_df.apply(pandas.to_numeric, errors='coerce').fillna(results_df) # type: ignore[assignment] # (fp)

# Concat the trials, configs, and results.
return trials_df.merge(configs_df, on=["trial_id", "tunable_config_id"], how="left") \
Expand Down

0 comments on commit 3a36797

Please sign in to comment.