Beispiel #1
0
    def compute_result_column_index(self):
        """
        Computes the column index of the result
        """
        value_names = self.value_names
        aggs_as_list = self.get_aggs_as_list()

        if isinstance(self.obj, cudf.Series):
            if len(aggs_as_list) == 1:
                if self.obj.name is None:
                    return self.obj.name
                else:
                    return [self.obj.name]
            else:
                return aggs_as_list
        else:
            return_multi_index = True
            if isinstance(self.original_aggs, str):
                return_multi_index = False
            if isinstance(self.original_aggs, collections.abc.Mapping):
                return_multi_index = False
                for key in self.original_aggs:
                    if not isinstance(self.original_aggs[key], str):
                        return_multi_index = True
                        break
            if return_multi_index:
                return MultiIndex.from_tuples(zip(value_names, aggs_as_list))
            else:
                return value_names
Beispiel #2
0
def test_multiindex_tuples(testarr):
    tuples = list(zip(*testarr[0]))

    index = MultiIndex.from_tuples(tuples, names=testarr[1])
    index_pd = pd.MultiIndex.from_tuples(tuples, names=testarr[1])

    assert index.is_unique == index_pd.is_unique
    assert index.is_monotonic == index_pd.is_monotonic
    assert index.is_monotonic_increasing == index_pd.is_monotonic_increasing
    assert index.is_monotonic_decreasing == index_pd.is_monotonic_decreasing
Beispiel #3
0
 def apply_multicolumn_mapped(self, result, aggs):
     if len(set(aggs.keys())) == len(aggs.keys()) and\
             isinstance(aggs[list(aggs.keys())[0]], (str, Number)):
         result.columns = aggs.keys()
     else:
         tuples = []
         for k in aggs.keys():
             for v in aggs[k]:
                 tuples.append((k, v))
         multiindex = MultiIndex.from_tuples(tuples)
         result.columns = multiindex
     return result
Beispiel #4
0
    def compute_result_column_index(self):
        """
        Computes the column index of the result
        """
        value_names = self.value_names
        aggs_as_list = self.get_aggs_as_list()

        if isinstance(self.obj, cudf.Series):
            if len(aggs_as_list) == 1:
                if self.obj.name is None:
                    return self.obj.name
                else:
                    return [self.obj.name]
            else:
                return aggs_as_list
        else:
            if len(aggs_as_list) == len(self.aggs):
                return value_names
            else:
                return MultiIndex.from_tuples(zip(value_names, aggs_as_list))
Beispiel #5
0
 def apply_multicolumn_mapped(self, result, aggs):
     # if all of the aggregations in the mapping set are only
     # length 1, we can assign the columns directly as keys.
     can_map_directly = True
     for values in aggs.values():
         value = [values] if isinstance(values, str) else list(values)
         if len(value) != 1:
             can_map_directly = False
             break
     if can_map_directly:
         result.columns = aggs.keys()
     else:
         tuples = []
         for k in aggs.keys():
             value = [aggs[k]] if isinstance(aggs[k], str) else list(
                     aggs[k])
             for v in value:
                 tuples.append((k, v))
         multiindex = MultiIndex.from_tuples(tuples)
         result.columns = multiindex
     return result