def load(self): if self.loaded: logger.info("Nothing to do. Symbol already loaded.") return if not self.file: raise Error( "Cannot load {} because there is no file pointer".format( repr(self))) if not self.index: raise Error( "Cannot load {} because there is no symbol index".format( repr(self))) if self.data_type == GamsDataType.Parameter and HAVE_GDX2PY: self.dataframe = gdx2py.par2list(self.file.filename, self.name) self._loaded = True return data = [] ret, records = gdxcc.gdxDataReadStrStart(self.file.H, self.index) for i in range(records): ret, elements, values, afdim = gdxcc.gdxDataReadStr(self.file.H) # make sure we pick value columns up correctly data.append( elements + [values[col_ind] for col_name, col_ind in self.value_cols]) if self.data_type == GamsDataType.Set: data[-1][-1] = True # gdxdict called gdxGetElemText here, but I do not currently see value in doing that self.dataframe = data if not self.data_type == GamsDataType.Set: self.dataframe = convert_gdx_to_np_svs(self.dataframe, self.num_dims, self.file) self._loaded = True return
def load(self): if self.loaded: logger.info("Nothing to do. Symbol already loaded.") return if not self.file: raise Error( "Cannot load {} because there is no file pointer".format( repr(self))) if not self.index: raise Error( "Cannot load {} because there is no symbol index".format( repr(self))) if self.data_type == GamsDataType.Parameter and HAVE_GDX2PY: self.dataframe = gdx2py.par2list(self.file.filename, self.name) self._loaded = True return _ret, records = gdxcc.gdxDataReadStrStart(self.file.H, self.index) def reader(): handle = self.file.H for i in range(records): yield gdxcc.gdxDataReadStr(handle) vc = self.value_cols # do this for speed in the next line data = [ elements + [values[col_ind] for col_name, col_ind in vc] for ret, elements, values, afdim in reader() ] # gdxdict called gdxGetElemText here, but I do not currently see value in doing that self.dataframe = data if not self.data_type == GamsDataType.Set: self.dataframe = special.convert_gdx_to_np_svs( self.dataframe, self.num_dims) self._loaded = True return