Skip to content

Commit bfb32c5

Browse files
mgarrardfacebook-github-bot
authored andcommitted
Fix ChainedAssignmentError in warm_start_from_old_experiment
Summary: Pandas 3.0 introduced Copy-on-Write (CoW) which makes chained assignment with `inplace=True` ineffective. The pattern `df["col"].replace(..., inplace=True)` no longer modifies the original DataFrame because the column selection creates a copy. Replace the chained `inplace=True` pattern with explicit assignment: - `df["col"].replace(..., inplace=True)` → `df["col"] = df["col"].replace(...)` This eliminates the `ChainedAssignmentError` warning and ensures the DataFrame is actually modified as intended. Differential Revision: D91187974
1 parent b49a247 commit bfb32c5

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

ax/core/experiment.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,12 +1409,11 @@ def warm_start_from_old_experiment(
14091409
has_data = not dat.df.empty
14101410
if has_data:
14111411
new_df = dat.full_df.copy()
1412-
new_df["trial_index"].replace(
1413-
{trial.index: new_trial.index}, inplace=True
1412+
new_df["trial_index"] = new_df["trial_index"].replace(
1413+
{trial.index: new_trial.index}
14141414
)
1415-
new_df["arm_name"].replace(
1416-
{none_throws(trial.arm).name: none_throws(new_trial.arm).name},
1417-
inplace=True,
1415+
new_df["arm_name"] = new_df["arm_name"].replace(
1416+
{none_throws(trial.arm).name: none_throws(new_trial.arm).name}
14181417
)
14191418
# Attach updated data to new trial on experiment.
14201419
self.attach_data(data=Data(df=new_df))

0 commit comments

Comments
 (0)