Query attribute `idval` from symbol `name`, and return a data structure shaped according to `reshape`.

def query(self, name, reshape=RESHAPE_DEFAULT, filt=None, idval=None, idxlower=True):
        '''
        Query attribute `idval` from symbol `name`, and return a data structure shaped according to `reshape`.
        '''
        gdx_handle = self.gdx_handle
        ret, symNr = gdxcc.gdxFindSymbol(gdx_handle, name)
        assert ret, "Symbol '%s' not found in GDX '%s'" % (name, self.internal_filename)
        sinfo = self.get_sid_info(symNr)
        dim = sinfo['dim']
        symType = sinfo['stype']
        ret, nrRecs = gdxcc.gdxDataReadStrStart(gdx_handle, symNr)
        assert ret, get_last_error('gdxDataReadStrStart', gdx_handle)
        if idval is None:
            if symType == gdxcc.GMS_DT_EQU:
                idval = gdxcc.GMS_VAL_MARGINAL
            else:
                idval = gdxcc.GMS_VAL_LEVEL
        ifilt = None
        vtable = [None]*(nrRecs)
        rcounter = 0
        rowtype = None
        if filt != None:
            if isinstance(filt,list):
                filt = '^({0})$'.format('|'.join([re.escape(x) for x in filt]))
            if isinstance(filt, str):
                filt_func = re.compile(filt, re.IGNORECASE).match
            else:
                filt_func = filt
        for i in range(nrRecs):
            vrow = [None]*(dim+1)
            ret, elements, values, afdim = gdxcc.gdxDataReadStr(gdx_handle)
            assert ret, get_last_error('gdxDataReadStr', gdx_handle)
            if (filt != None):
                match_filt = False
                for e in elements:
                    m = filt_func(e)
                    if m != None:
                        match_filt = True
                        break
                if not match_filt:
                    continue
            d = -1
            for d in range(dim):
                try:
                    vrow[d] = int(elements[d])
                except:
                    vrow[d] = elements[d].lower() if idxlower else elements[d]
            vrow[d+1] = values[idval]
            vtable[rcounter] = vrow
            rcounter += 1
        gdxcc.gdxDataReadDone(gdx_handle)
        cols = ['s%d' % x for x in range(dim)]+['val',]
        df = pd.DataFrame(vtable[:rcounter],columns=cols)
        logger.debug("%d / %d records read from <%s>" % (rcounter, nrRecs, self.internal_filename))
        if symType == gdxcc.GMS_DT_SET:
            reshape = RESHAPE_SERIES
        df = dfreshape(df, reshape)
        if symType == gdxcc.GMS_DT_SET:
            df = df.index
        self.data = df
        return df