def get_result(self): # series only if self._is_series: # stack blocks if self.bm_axis == 0: name = com.consensus_name_attr(self.objs) cons = self.objs[0]._constructor arrs = [ser._values for ser in self.objs] res = concat_compat(arrs, axis=0) result = cons(res, index=self.new_axes[0], name=name, dtype=res.dtype) return result.__finalize__(self, method="concat") # combine as columns in a frame else: data = dict(zip(range(len(self.objs)), self.objs)) # GH28330 Preserves subclassed objects through concat cons = self.objs[0]._constructor_expanddim index, columns = self.new_axes df = cons(data, index=index) df.columns = columns return df.__finalize__(self, method="concat") # combine block managers else: mgrs_indexers = [] for obj in self.objs: indexers = {} for ax, new_labels in enumerate(self.new_axes): # ::-1 to convert BlockManager ax to DataFrame ax if ax == self.bm_axis: # Suppress reindexing on concat axis continue # 1-ax to convert BlockManager axis to DataFrame axis obj_labels = obj.axes[1 - ax] if not new_labels.equals(obj_labels): indexers[ax] = obj_labels.reindex(new_labels)[1] mgrs_indexers.append((obj._mgr, indexers)) new_data = concatenate_block_managers( mgrs_indexers, self.new_axes, concat_axis=self.bm_axis, copy=self.copy, ) if not self.copy: new_data._consolidate_inplace() cons = self.objs[0]._constructor return cons(new_data).__finalize__(self, method="concat")
def get_result(self): # series only if self._is_series: # stack blocks if self.axis == 0: name = com.consensus_name_attr(self.objs) mgr = self.objs[0]._data.concat([x._data for x in self.objs], self.new_axes) cons = _concat._get_series_result_type(mgr, self.objs) return cons(mgr, name=name).__finalize__(self, method="concat") # combine as columns in a frame else: data = dict(zip(range(len(self.objs)), self.objs)) cons = _concat._get_series_result_type(data) index, columns = self.new_axes df = cons(data, index=index) df.columns = columns return df.__finalize__(self, method="concat") # combine block managers else: mgrs_indexers = [] for obj in self.objs: mgr = obj._data indexers = {} for ax, new_labels in enumerate(self.new_axes): if ax == self.axis: # Suppress reindexing on concat axis continue obj_labels = mgr.axes[ax] if not new_labels.equals(obj_labels): indexers[ax] = obj_labels.reindex(new_labels)[1] mgrs_indexers.append((obj._data, indexers)) new_data = concatenate_block_managers(mgrs_indexers, self.new_axes, concat_axis=self.axis, copy=self.copy) if not self.copy: new_data._consolidate_inplace() cons = _concat._get_frame_result_type(new_data, self.objs) return cons._from_axes(new_data, self.new_axes).__finalize__(self, method="concat")
def get_result(self): # series only if self._is_series: # stack blocks if self.bm_axis == 0: name = com.consensus_name_attr(self.objs) mgr = self.objs[0]._mgr.concat([x._mgr for x in self.objs], self.new_axes[0]) cons = self.objs[0]._constructor return cons(mgr, name=name).__finalize__(self, method="concat") # combine as columns in a frame else: data = dict(zip(range(len(self.objs)), self.objs)) cons = DataFrame index, columns = self.new_axes df = cons(data, index=index) df.columns = columns return df.__finalize__(self, method="concat") # combine block managers else: mgrs_indexers = [] for obj in self.objs: indexers = {} for ax, new_labels in enumerate(self.new_axes): # ::-1 to convert BlockManager ax to DataFrame ax if ax == self.bm_axis: # Suppress reindexing on concat axis continue # 1-ax to convert BlockManager axis to DataFrame axis obj_labels = obj.axes[1 - ax] if not new_labels.equals(obj_labels): indexers[ax] = obj_labels.reindex(new_labels)[1] mgrs_indexers.append((obj._mgr, indexers)) new_data = concatenate_block_managers(mgrs_indexers, self.new_axes, concat_axis=self.bm_axis, copy=self.copy) if not self.copy: new_data._consolidate_inplace() cons = self.objs[0]._constructor return cons(new_data).__finalize__(self, method="concat")
def get_result(self): # series only if self._is_series: # stack blocks if self.axis == 0: name = com.consensus_name_attr(self.objs) mgr = self.objs[0]._data.concat([x._data for x in self.objs], self.new_axes) cons = _concat._get_series_result_type(mgr, self.objs) return cons(mgr, name=name).__finalize__(self, method='concat') # combine as columns in a frame else: data = dict(zip(range(len(self.objs)), self.objs)) cons = _concat._get_series_result_type(data) index, columns = self.new_axes df = cons(data, index=index) df.columns = columns return df.__finalize__(self, method='concat') # combine block managers else: mgrs_indexers = [] for obj in self.objs: mgr = obj._data indexers = {} for ax, new_labels in enumerate(self.new_axes): if ax == self.axis: # Suppress reindexing on concat axis continue obj_labels = mgr.axes[ax] if not new_labels.equals(obj_labels): indexers[ax] = obj_labels.reindex(new_labels)[1] mgrs_indexers.append((obj._data, indexers)) new_data = concatenate_block_managers( mgrs_indexers, self.new_axes, concat_axis=self.axis, copy=self.copy) if not self.copy: new_data._consolidate_inplace() cons = _concat._get_frame_result_type(new_data, self.objs) return (cons._from_axes(new_data, self.new_axes) .__finalize__(self, method='concat'))
def get_result(self): cons: Type[FrameOrSeriesUnion] sample: FrameOrSeriesUnion # series only if self._is_series: sample = cast("Series", self.objs[0]) # stack blocks if self.bm_axis == 0: name = com.consensus_name_attr(self.objs) cons = sample._constructor arrs = [ser._values for ser in self.objs] res = concat_compat(arrs, axis=0) result = cons(res, index=self.new_axes[0], name=name, dtype=res.dtype) return result.__finalize__(self, method="concat") # combine as columns in a frame else: data = dict(zip(range(len(self.objs)), self.objs)) # GH28330 Preserves subclassed objects through concat cons = sample._constructor_expanddim index, columns = self.new_axes df = cons(data, index=index) df.columns = columns return df.__finalize__(self, method="concat") # combine block managers else: sample = cast("DataFrame", self.objs[0]) mgrs_indexers = [] for obj in self.objs: indexers = {} for ax, new_labels in enumerate(self.new_axes): # ::-1 to convert BlockManager ax to DataFrame ax if ax == self.bm_axis: # Suppress reindexing on concat axis continue # 1-ax to convert BlockManager axis to DataFrame axis obj_labels = obj.axes[1 - ax] if not new_labels.equals(obj_labels): # We have to remove the duplicates from obj_labels # in new labels to make them unique, otherwise we would # duplicate or duplicates again if not obj_labels.is_unique: new_labels = algos.make_duplicates_of_left_unique_in_right( np.asarray(obj_labels), np.asarray(new_labels)) indexers[ax] = obj_labels.reindex(new_labels)[1] mgrs_indexers.append((obj._mgr, indexers)) new_data = concatenate_block_managers(mgrs_indexers, self.new_axes, concat_axis=self.bm_axis, copy=self.copy) if not self.copy: new_data._consolidate_inplace() cons = sample._constructor return cons(new_data).__finalize__(self, method="concat")