def _update_df(self, change=None): """ Updates the stored DataFrame with respect to the actual values of the Sheet. Then updates the file with respect to the stored DataFrame. """ frames = [ self._sheet_to_df(self._design_var_sheet), self._sheet_to_df(self._constraint_sheet), self._sheet_to_df(self._objective_sheet), ] df = pd.concat(frames, sort=True) columns = {} columns.update(self._DEFAULT_COLUMN_RENAMING) columns.pop("type") column_to_attribute = {value: key for key, value in columns.items()} variables = VariableList.from_dataframe( df[column_to_attribute.keys()].rename(columns=column_to_attribute)) attribute_to_column = columns df = (variables.to_dataframe().rename(columns=attribute_to_column)[ attribute_to_column.values()].reset_index(drop=True)) rows = df.index.tolist() columns = df.columns.tolist() for r in rows: for c in columns: self.dataframe.loc[int(r), c] = df.loc[r, c]
def get_variables(self, column_to_attribute: Dict[str, str] = None) -> VariableList: """ :param column_to_attribute: dictionary keys tell what columns are kept and the values tell what variable attribute it corresponds to. If not provided, default translation will apply. :return: a variable list from current data set """ if not column_to_attribute: column_to_attribute = { value: key for key, value in self._DEFAULT_COLUMN_RENAMING.items() } df = self.dataframe.copy() df["is_input"] = None df.loc[df["I/O"] == INPUT, "is_input"] = True df.loc[df["I/O"] == OUTPUT, "is_input"] = False df.drop(columns=["I/O"], inplace=True) variables = VariableList.from_dataframe( df[column_to_attribute.keys()].rename(columns=column_to_attribute)) return variables
def get_variables(self, column_to_attribute: Dict[str, str] = None) -> VariableList: """ :param column_to_attribute: dictionary keys tell what columns are kept and the values tell whatvariable attribute it corresponds to. If not provided, default translation will apply. :return: a variable list from current data set """ if not column_to_attribute: column_to_attribute = { value: key for key, value in self._DEFAULT_COLUMN_RENAMING.items() } return VariableList.from_dataframe( self.dataframe[column_to_attribute.keys()].rename(columns=column_to_attribute) )