def addColumns(self, **kwargs): """ Add new columns with default values (type inferred from it). """ items = self.first()._asdict().items() cols = [Table.Column(k, type(v)) for k, v in items] for k, v in kwargs.items(): cols.append(Table.Column(k, type(v))) t = Table(columns=cols) for og in self._dict.values(): values = og._asdict() values.update(kwargs) t.addRow(**values) self.__fromTable(t)
def _createTableFromDict(self, rowDict): """ Helper function to create a Table instance from an input dict with keys as columns names and type the type of the values in the dict. """ return Table(columns=[ Table.Column(k, type=type(v)) for k, v in rowDict.items() ])
def _write(self, f): # Create columns from the first row items = self.first()._asdict().items() cols = [Table.Column(k, type(v)) for k, v in items] t = Table(columns=cols) for og in self._dict.values(): t.addRow(*og) t.writeStar(f, tableName='optics')