Add helper methods for appending data to a gdxpds.gdx.GdxFile
elainethale opened this issue · 1 comments
elainethale commented
E.g.
def append_set(gdx_file, set_name, df, cols=None, dim_names=None,
description=None):
# ensure df is DataFrame and not Series
logger.debug("Defining set based on:\n{!r}".format(df))
tmp = pd.DataFrame(df)
# select down to data we actually want
if cols is not None:
tmp = tmp[cols]
if dim_names is not None:
tmp.columns = dim_names
# define the symbol
logger.debug("After processing, set will be defined using:\n{!r}".format(tmp))
gdx_file.append(gdxpds.gdx.GdxSymbol(set_name, gdxpds.gdx.GamsDataType.Set,
dims = list(tmp.columns), description = description))
# define the data for the symbol
gdx_file[-1].dataframe = tmp
return
def append_parameter(gdx_file, param_name, df, cols=None, dim_names=None,
description=None):
# pre-process the data
logger.debug("Defining parameter based on:\n{!r}".format(df))
tmp = df.copy()
if cols is not None:
tmp = tmp[cols]
if dim_names is not None:
tmp.columns = dim_names + ['Value']
# define the symbol
logger.debug("After processing, parameter will be defined using:\n{!r}".format(tmp))
gdx_file.append(gdxpds.gdx.GdxSymbol(param_name, gdxpds.gdx.GamsDataType.Parameter,
dims = list(tmp.columns)[:-1], description = description))
# define the data for the symbol
gdx_file[-1].dataframe = tmp
return
elainethale commented
Has been available for awhile now.