예제 #1
0
    def pd_multi_index_from_product_impl(cls,
                                         iterables,
                                         sortorder=None,
                                         names=None):

        # TO-DO: support indexes.unique() method and use it here
        levels_factorized = sdc_tuple_map(factorize_level, iterables)

        levels_names = sdc_tuple_map(sdc_indexes_get_name, iterables)

        index_levels = sdc_tuple_map(lambda x: fix_df_index(list(x[0])),
                                     levels_factorized)

        temp_cumprod_sizes = [
            1,
        ]
        codes_info = sdc_tuple_map(next_codes_info, levels_factorized,
                                   temp_cumprod_sizes)

        res_index_size = temp_cumprod_sizes[-1]
        index_codes = sdc_tuple_map(next_codes_array, codes_info,
                                    res_index_size)

        res = sdc_pandas_multi_index_ctor(index_levels,
                                          index_codes,
                                          name=levels_names)

        return res
예제 #2
0
        def pd_multi_index_getitem_idx_bool_array_impl(self, idx):

            new_levels = self._levels
            new_codes = sdc_tuple_map(
                lambda arr_codes, taken_idxs: numpy_like.getitem_by_mask(
                    arr_codes, taken_idxs), self._codes, idx)
            return pd.MultiIndex(new_levels, new_codes)
예제 #3
0
        def pd_multi_index_getitem_idx_slice_impl(self, idx):

            new_levels = self._levels
            new_codes = sdc_tuple_map(
                lambda arr_codes, taken_idxs: arr_codes[taken_idxs],
                self._codes, idx)
            return pd.MultiIndex(new_levels, new_codes)
예제 #4
0
    def pd_multi_index_ctor_impl(levels,
                                 codes,
                                 sortorder=None,
                                 names=None,
                                 dtype=None,
                                 copy=False,
                                 name=None):

        if len(levels) != len(codes):
            raise ValueError("Length of levels and codes must be the same.")
        if len(levels) == 0:
            raise ValueError("Must pass non-zero number of levels/codes")

        # if name is None then all level names are reset
        if is_name_none == True:  # noqa
            _names = sdc_tuple_map(
                lambda x: None,
                levels,
            )
        else:
            _names = name

        levels_and_codes_pairs = sdc_tuple_map_elementwise(
            _multi_index_create_levels_and_codes, levels, codes, _names)

        _levels, _codes = sdc_tuple_unzip(levels_and_codes_pairs)
        return init_multi_index(_levels, _codes)
예제 #5
0
    def pd_multi_index_append_impl(self, other):

        self_and_other_data = _multi_index_binop_helper(self, other)
        tup_append_level_res = sdc_tuple_map(
            lambda x: _multi_index_append_level(*x), self_and_other_data)

        new_levels, new_codes = sdc_tuple_unzip(tup_append_level_res)
        return pd.MultiIndex(levels=new_levels, codes=new_codes)
예제 #6
0
    def pd_multi_index_names_impl(self):
        levels_names = sdc_tuple_map(lambda x: x.name, self._levels)

        # this exploits undesired side-effect of literal_unroll - type-unification
        # of resulting list dtype that will be types.Optional(types.unicode_type)
        # as using typed.List of Optional values currently fails to compile
        res = []
        for i in literal_unroll(levels_names):
            res.append(i)
        return res
예제 #7
0
    def pd_multi_index_type_from_tuples_impl(cls, iterables):

        index_size = len(iterables)
        if not index_size:
            raise TypeError("Cannot infer number of levels from empty list")

        # use first value to infer types and allocate dicts for result multi index levels
        example_value = iterables[0]
        levels_dicts = sdc_tuple_map(_multi_index_alloc_level_dict,
                                     example_value)
        index_codes = sdc_tuple_map(
            lambda _, size: np.empty(size, dtype=types.int64), example_value,
            index_size)

        for i, val in enumerate(iterables):
            _multi_index_from_tuples_helper(val, levels_dicts, index_codes, i)

        index_levels = sdc_tuple_map(lambda x: list(x.keys()), levels_dicts)

        res = pd.MultiIndex(
            levels=index_levels,
            codes=index_codes,
        )
        return res
예제 #8
0
    def pd_multi_index_equals_impl(self, other):

        if self.nlevels != other.nlevels:
            return False

        self_and_other_data = _multi_index_binop_helper(self, other)
        tup_levels_cmp_res = sdc_tuple_map(
            lambda x: cat_array_equal(*x),
            self_and_other_data,
        )

        # np.all is not supported for Tuples and below compiles a bit faster
        # than 'np.all(np.array(list(tup_levels_cmp_res)))'
        for cmp_res in tup_levels_cmp_res:
            if not cmp_res:
                return False
        return True
예제 #9
0
 def pd_multi_index_take_impl(self, indexes):
     new_levels = self._levels
     new_codes = sdc_tuple_map(
         lambda idx, taken_idxs: sdc_indexes_take(idx, taken_idxs),
         self._codes, indexes)
     return pd.MultiIndex(new_levels, new_codes)