def _reindex_columns(self, columns): if len(columns) == 0: return DataMatrix(index=self.index) if not isinstance(columns, Index): columns = Index(columns) if self.objects is not None: object_columns = columns.intersection(self.objects.columns) columns = columns - object_columns objects = self.objects._reindex_columns(object_columns) else: objects = None if len(columns) > 0 and len(self.columns) == 0: return DataMatrix(index=self.index, columns=columns, objects=objects) indexer, mask = common.get_indexer(self.columns, columns, None) mat = self.values.take(indexer, axis=1) notmask = -mask if len(mask) > 0: if notmask.any(): if issubclass(mat.dtype.type, np.int_): mat = mat.astype(float) elif issubclass(mat.dtype.type, np.bool_): mat = mat.astype(float) common.null_out_axis(mat, notmask, 1) return DataMatrix(mat, index=self.index, columns=columns, objects=objects)
def _reindex_index(self, index, method): if index is self.index: return self.copy() if not isinstance(index, Index): index = Index(index) if len(self.index) == 0: return DataMatrix(index=index, columns=self.columns) indexer, mask = common.get_indexer(self.index, index, method) mat = self.values.take(indexer, axis=0) notmask = -mask if len(index) > 0: if notmask.any(): if issubclass(mat.dtype.type, np.int_): mat = mat.astype(float) elif issubclass(mat.dtype.type, np.bool_): mat = mat.astype(float) common.null_out_axis(mat, notmask, 0) if self.objects is not None and len(self.objects.columns) > 0: newObjects = self.objects.reindex(index) else: newObjects = None return DataMatrix(mat, index=index, columns=self.columns, objects=newObjects)
def reindex_axis(self, indexer, notmask, needs_masking, axis=0): """ Reindex using pre-computed indexer information """ if self.values.size > 0: new_values = self.values.take(indexer, axis=axis) else: shape = list(self.shape) shape[axis] = len(indexer) new_values = np.empty(shape) new_values.fill(np.nan) if needs_masking: new_values = _cast_if_bool_int(new_values) common.null_out_axis(new_values, notmask, axis) return make_block(new_values, self.items, self.ref_items)