in src/alpaca_eval/processors.py [0:0]
def _switch_or_unswitch(self, df: pd.DataFrame, is_switch: bool) -> pd.DataFrame:
"""Applies the switch to the dataframe. If `is_switch=False` will undo the switch."""
# switching two columns is an involution => no need to use is_switch here
col1_values = df[self.col1].copy()
col2_values = df[self.col2].copy()
is_switch_arr = df[self._switch_column]
df[self.col2] = np.where(is_switch_arr, col1_values, col2_values)
df[self.col1] = np.where(is_switch_arr, col2_values, col1_values)
if is_switch:
df.loc[is_switch_arr, :] = self.fn_replace_if_switch(df.loc[is_switch_arr, :])
else:
df.loc[is_switch_arr, :] = self.fn_replace_if_unswitch(df.loc[is_switch_arr, :])
return df