def __getitem__(self, item): if isinstance(item, str): if item in self.colnames: return self.columns[item] else: return Column([cmd['params'].get(item) for cmd in self], name=item) elif isinstance(item, int): return CommandRow(self, item) elif isinstance(item, (tuple, list)) and all(x in self.colnames for x in item): from copy import deepcopy from astropy.table import groups out = self.__class__([self[x] for x in item], meta=deepcopy(self.meta)) out._groups = groups.TableGroups(out, indices=self.groups._indices, keys=self.groups._keys) return out elif (isinstance(item, slice) or isinstance(item, np.ndarray) or isinstance(item, list) or isinstance(item, tuple) and all(isinstance(x, np.ndarray) for x in item)): # here for the many ways to give a slice; a tuple of ndarray # is produced by np.where, as in t[np.where(t['a'] > 2)] # For all, a new table is constructed with slice of all columns return self._new_from_slice(item) else: raise ValueError('Illegal type {0} for table item access'.format( type(item)))
def __getitem__(self, item): if self._is_list_or_tuple_of_str(item): if 'time' not in item: out = QTable([self[x] for x in item], meta=deepcopy(self.meta), copy_indices=self._copy_indices) out._groups = groups.TableGroups(out, indices=self.groups._indices, keys=self.groups._keys) return out return super().__getitem__(item)