예제 #1
0
파일: join.py 프로젝트: TravisHester/cudf
 def _sort_result(self, result: Frame) -> Frame:
     # Pandas sorts on the key columns in the
     # same order as given in 'on'. If the indices are used as
     # keys, the index will be sorted. If one index is specified,
     # the key columns on the other side will be used to sort.
     if self.on:
         if isinstance(result, cudf.BaseIndex):
             sort_order = result._get_sorted_inds()
         else:
             # need a list instead of a tuple here because
             # _get_sorted_inds calls down to ColumnAccessor.get_by_label
             # which handles lists and tuples differently
             sort_order = result._get_sorted_inds(
                 list(_coerce_to_tuple(self.on)))
         return result._gather(sort_order, keep_index=False)
     by = []
     if self.left_index and self.right_index:
         if result._index is not None:
             by.extend(result._index._data.columns)
     if self.left_on:
         by.extend(
             [result._data[col] for col in _coerce_to_tuple(self.left_on)])
     if self.right_on:
         by.extend(
             [result._data[col] for col in _coerce_to_tuple(self.right_on)])
     if by:
         to_sort = cudf.DataFrame._from_columns(by)
         sort_order = to_sort.argsort()
         result = result._gather(sort_order)
     return result
예제 #2
0
 def _sort_result(self, result: Frame) -> Frame:
     # Pandas sorts on the key columns in the
     # same order as given in 'on'. If the indices are used as
     # keys, the index will be sorted. If one index is specified,
     # the key columns on the other side will be used to sort.
     by: List[Any] = []
     if self._using_left_index and self._using_right_index:
         if result._index is not None:
             by.extend(result._index._data.columns)
     if not self._using_left_index:
         by.extend([result._data[col.name] for col in self._left_keys])
     if not self._using_right_index:
         by.extend([result._data[col.name] for col in self._right_keys])
     if by:
         to_sort = cudf.DataFrame._from_data(dict(enumerate(by)))
         sort_order = to_sort.argsort()
         if isinstance(result, cudf.core._base_index.BaseIndex):
             result = result._gather(sort_order, check_bounds=False)
         else:
             result = cast(cudf.core.indexed_frame.IndexedFrame, result)
             result = result._gather(
                 sort_order,
                 keep_index=self._using_left_index
                 or self._using_right_index,
                 check_bounds=False,
             )
     return result