(arr, index, name, by_index)
return sdc_reindex_series_impl
Reindexes series data by new index following the logic of pandas.core.indexing.check_bool_indexer
Reindexes series data by new index following the logic of pandas.core.indexing.check_bool_indexer
Reindexes series data by new index following the logic of pandas . core . indexing . check_bool_indexer
def sdc_reindex_series_overload(arr, index, name, by_index):
    """ Reindexes series data by new index following the logic of pandas.core.indexing.check_bool_indexer """

    range_indexes = (isinstance(index, (PositionalIndexType, RangeIndexType))
                     and isinstance(by_index, (PositionalIndexType, RangeIndexType)))
    data_dtype, index_dtype = arr.dtype, index.dtype
    data_is_str_arr = isinstance(arr.dtype, types.UnicodeType)

    # use old implementation if old indexes types are used
    if (isinstance(index, sdc_old_index_types) or isinstance(by_index, sdc_old_index_types)):

        def sdc_reindex_series_old_impl(arr, index, name, by_index):

            # no reindexing is needed if indexes are equal, but only check if it's fast
            if range_indexes == True:  # noqa
                equal_indexes = index.equals(by_index)
            else:
                equal_indexes = False
            if (index is by_index or equal_indexes):
                return pandas.Series(data=arr, index=by_index, name=name)

            if data_is_str_arr == True:  # noqa
                _res_data = [''] * len(by_index)
                res_data_nan_mask = numpy.zeros(len(by_index), dtype=types.bool_)
            else:
                _res_data = numpy.empty(len(by_index), dtype=data_dtype)

            # build a dict of self.index values to their positions:
            map_index_to_position = Dict.empty(
                key_type=index_dtype,
                value_type=types.int32
            )

            for i, value in enumerate(index):
                if value in map_index_to_position:
                    raise ValueError("cannot reindex from a duplicate axis")
                else:
                    map_index_to_position[value] = i

            index_mismatch = 0
            for i in numba.prange(len(by_index)):
                val = by_index[i]
                if val in map_index_to_position:
                    pos_in_self = map_index_to_position[val]
                    _res_data[i] = arr[pos_in_self]
                    if data_is_str_arr == True:  # noqa
                        res_data_nan_mask[i] = isna(arr, i)
                else:
                    index_mismatch += 1
            if index_mismatch:
                msg = "Unalignable boolean Series provided as indexer " + \
                      "(index of the boolean Series and of the indexed object do not match)."
                raise IndexingError(msg)

            if data_is_str_arr == True:  # noqa
                res_data = create_str_arr_from_list(_res_data)
                str_arr_set_na_by_mask(res_data, res_data_nan_mask)
            else:
                res_data = _res_data

            return pandas.Series(data=res_data, index=by_index, name=name)

        return sdc_reindex_series_old_impl

    def sdc_reindex_series_impl(arr, index, name, by_index):

        _, new_order = index.reindex(by_index)
        if new_order is not None:
            new_order_as_array = _nonoptional(new_order)
            index_mismatch = 0
            for i in numba.prange(len(by_index)):
                if new_order_as_array[i] == -1:
                    index_mismatch += 1

            if index_mismatch:
                # TO-DO: seems it covers only specific series reindex case, generalize?
                msg = "Unalignable boolean Series provided as indexer " + \
                      "(index of the boolean Series and of the indexed object do not match)."
                raise IndexingError(msg)

            res_data = numpy_like.take(arr, new_order_as_array)
        else:
            res_data = arr

        return pandas.Series(data=res_data, index=by_index, name=name)

    return sdc_reindex_series_impl
def sdc_reindex_series_overload ( arr , index , name , by_index ) : range_indexes = ( isinstance ( index , ( PositionalIndexType , RangeIndexType ) ) and isinstance ( by_index , ( PositionalIndexType , RangeIndexType ) ) ) data_dtype , index_dtype = arr . dtype , index . dtype data_is_str_arr = isinstance ( arr . dtype , types . UnicodeType ) # use old implementation if old indexes types are used if ( isinstance ( index , sdc_old_index_types ) or isinstance ( by_index , sdc_old_index_types ) ) : def sdc_reindex_series_old_impl ( arr , index , name , by_index ) : # no reindexing is needed if indexes are equal, but only check if it's fast if range_indexes == True : # noqa equal_indexes = index . equals ( by_index ) else : equal_indexes = False if ( index is by_index or equal_indexes ) : return pandas . Series ( data = arr , index = by_index , name = name ) if data_is_str_arr == True : # noqa _res_data = [ '' ] * len ( by_index ) res_data_nan_mask = numpy . zeros ( len ( by_index ) , dtype = types . bool_ ) else : _res_data = numpy . empty ( len ( by_index ) , dtype = data_dtype ) # build a dict of self.index values to their positions: map_index_to_position = Dict . empty ( key_type = index_dtype , value_type = types . int32 ) for i , value in enumerate ( index ) : if value in map_index_to_position : raise ValueError ( "cannot reindex from a duplicate axis" ) else : map_index_to_position [ value ] = i index_mismatch = 0 for i in numba . prange ( len ( by_index ) ) : val = by_index [ i ] if val in map_index_to_position : pos_in_self = map_index_to_position [ val ] _res_data [ i ] = arr [ pos_in_self ] if data_is_str_arr == True : # noqa res_data_nan_mask [ i ] = isna ( arr , i ) else : index_mismatch += 1 if index_mismatch : msg = "Unalignable boolean Series provided as indexer " + "(index of the boolean Series and of the indexed object do not match)." raise IndexingError ( msg ) if data_is_str_arr == True : # noqa res_data = create_str_arr_from_list ( _res_data ) str_arr_set_na_by_mask ( res_data , res_data_nan_mask ) else : res_data = _res_data return pandas . Series ( data = res_data , index = by_index , name = name ) return sdc_reindex_series_old_impl def sdc_reindex_series_impl ( arr , index , name , by_index ) : _ , new_order = index . reindex ( by_index ) if new_order is not None : new_order_as_array = _nonoptional ( new_order ) index_mismatch = 0 for i in numba . prange ( len ( by_index ) ) : if new_order_as_array [ i ] == - 1 : index_mismatch += 1 if index_mismatch : # TO-DO: seems it covers only specific series reindex case, generalize? msg = "Unalignable boolean Series provided as indexer " + "(index of the boolean Series and of the indexed object do not match)." raise IndexingError ( msg ) res_data = numpy_like . take ( arr , new_order_as_array ) else : res_data = arr return pandas . Series ( data = res_data , index = by_index , name = name ) return sdc_reindex_series_impl