Exemplo n.º 1
0
    def sdc_reindex_series_impl(arr, index, name, by_index):

        # no reindexing is needed if indexes are equal
        if range_indexes == True:  # noqa
            equal_indexes = numpy_like.array_equal(index, by_index)
        elif int64_indexes == True:  # noqa
            equal_indexes = numpy_like.array_equal(index, 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)
Exemplo n.º 2
0
 def sdc_join_range_indexes_impl(left, right):
     if (left is right or numpy_like.array_equal(left, right)):
         joined = left.values
         lidx = numpy.arange(len(joined))
         ridx = lidx
         return joined, lidx, ridx
     else:
         return sdc_join_series_indexes(left.values, right.values)
Exemplo n.º 3
0
        def pd_indexes_join_array_indexes_impl(left, right):

            _left = left.values if convert_left == True else left  # noqa
            _right = right.values if convert_right == True else right  # noqa
            if (_left is _right or numpy_like.array_equal(_left, _right)):
                if index_dtypes_match == False:  # noqa
                    joined_index = numpy_like.astype(_left, res_index_dtype)
                else:
                    joined_index = _left
                return joined_index, None, None

            return _sdc_internal_join(_left, _right)
Exemplo n.º 4
0
            def _series_comp_binop_common_impl(self, other, fill_value=None):

                left_index, right_index = self.index, other.index
                if not (left_index is right_index
                        or numpy_like.array_equal(left_index, right_index)):
                    raise ValueError(
                        "Can only compare identically-labeled Series objects")

                _left, _right = pandas.Series(self._data), pandas.Series(
                    other._data)
                partial_res = _left.comp_binop(_right, fill_value=fill_value)

                if index_dtypes_match == False:  # noqa
                    result_index = numpy_like.astype(left_index,
                                                     numba_index_common_dtype)
                else:
                    result_index = left_index.values if left_index_is_range == True else left_index  # noqa

                return pandas.Series(partial_res._data, result_index)
Exemplo n.º 5
0
            def _series_comp_binop_common_impl(self,
                                               other,
                                               level=None,
                                               fill_value=None,
                                               axis=0):
                numpy_like.fillna(self._data, inplace=True, value=fill_value)
                numpy_like.fillna(other._data, inplace=True, value=fill_value)
                left_index, right_index = self.index, other.index

                if (left_index is right_index
                        or numpy_like.array_equal(left_index, right_index)):
                    if index_dtypes_match == False:  # noqa
                        new_index = numpy_like.astype(
                            left_index, numba_index_common_dtype)
                    else:
                        new_index = left_index.values if left_index_is_range == True else left_index  # noqa
                    return pandas.Series(self._data < other._data, new_index)
                else:
                    raise ValueError(
                        "Can only compare identically-labeled Series objects")
Exemplo n.º 6
0
            def _series_binop_common_impl(self,
                                          other,
                                          level=None,
                                          fill_value=None,
                                          axis=0):
                left_index, right_index = self.index, other.index
                numpy_like.fillna(self._data, inplace=True, value=fill_value)
                numpy_like.fillna(other._data, inplace=True, value=fill_value)
                if check_index_equal == True:  # noqa
                    equal_indexes = numpy_like.array_equal(
                        left_index, right_index)
                else:
                    equal_indexes = False

                if (left_index is right_index or equal_indexes):
                    result_data = numpy.empty(len(self._data),
                                              dtype=numpy.float64)
                    result_data[:] = self._data + other._data
                    if index_dtypes_match == False:  # noqa
                        result_index = numpy_like.astype(
                            left_index, numba_index_common_dtype)
                    else:
                        result_index = left_index.values if left_index_is_range == True else left_index  # noqa

                    return pandas.Series(result_data, index=result_index)

                # TODO: replace below with core join(how='outer', return_indexers=True) when implemented
                joined_index, left_indexer, right_indexer = sdc_join_series_indexes(
                    left_index, right_index)
                result_size = len(joined_index)
                left_values = numpy.empty(result_size, dtype=numpy.float64)
                right_values = numpy.empty(result_size, dtype=numpy.float64)
                _fill_value = numpy.nan if fill_value_is_none == True else fill_value  # noqa
                for i in range(result_size):
                    left_pos, right_pos = left_indexer[i], right_indexer[i]
                    left_values[i] = self._data[
                        left_pos] if left_pos != -1 else _fill_value
                    right_values[i] = other._data[
                        right_pos] if right_pos != -1 else _fill_value
                result_data = left_values + right_values
                return pandas.Series(result_data, joined_index)
Exemplo n.º 7
0
            def sdc_binop_impl(self, other, fill_value=None):

                # check if indexes are equal and series don't have to be aligned
                left_index, right_index = self.index, other.index
                if (left_index is right_index
                        or numpy_like.array_equal(left_index, right_index)):

                    _left = pandas.Series(self._data)
                    _right = pandas.Series(other._data)
                    partial_res = _left.binop(_right, fill_value=fill_value)

                    if index_dtypes_match == False:  # noqa
                        result_index = numpy_like.astype(
                            left_index, numba_index_common_dtype)
                    else:
                        result_index = left_index.values if left_index_is_range == True else left_index  # noqa

                    return pandas.Series(partial_res._data, index=result_index)

                _fill_value = numpy.nan if fill_value_is_none == True else fill_value  # noqa
                # TODO: replace below with core join(how='outer', return_indexers=True) when implemented
                joined_index, left_indexer, right_indexer = sdc_join_series_indexes(
                    left_index, right_index)
                result_size = len(joined_index)
                result_data = numpy.empty(result_size, dtype=numpy.float64)
                for i in numba.prange(result_size):
                    left_pos, right_pos = left_indexer[i], right_indexer[i]
                    left_nan = (left_pos == -1
                                or numpy.isnan(self._data[left_pos]))
                    right_nan = (right_pos == -1
                                 or numpy.isnan(other._data[right_pos]))
                    _left = _fill_value if left_nan else self._data[left_pos]
                    _right = _fill_value if right_nan else other._data[
                        right_pos]
                    result_data[i] = numpy.nan if (
                        left_nan and right_nan) else _left + _right

                return pandas.Series(result_data, index=joined_index)
Exemplo n.º 8
0
        def _series_lt_common_impl(self, other, fill_value=None):

            left_index, right_index = self.index, other.index
            if index_api_supported == True:  # noqa
                if not (left_index is right_index or left_index.equals(right_index)):
                    raise ValueError("Can only compare identically-labeled Series objects")
            else:
                if not (left_index is right_index or numpy_like.array_equal(left_index, right_index)):
                    raise ValueError("Can only compare identically-labeled Series objects")

            res_size = len(left_index)
            if fill_value_is_none == True:  # noqa
                res_data = self._data < other._data
            else:
                res_data = numpy.empty(res_size, dtype=types.bool_)
                for i in numba.prange(res_size):
                    left_nan = isna(self._data, i)
                    right_nan = isna(other._data, i)
                    _left = fill_value if left_nan else self._data[i]
                    _right = fill_value if right_nan else other._data[i]
                    res_data[i] = False if (left_nan and right_nan) else _left < _right

            res_index = sdc_unify_index_types(left_index, right_index)
            return pandas.Series(res_data, index=res_index)
Exemplo n.º 9
0
 def sdc_func(index1, index2):
     return array_equal(index1, index2)
Exemplo n.º 10
0
    def sdc_numeric_indexes_equals_impl(left, right):
        left = left.values if convert_A == True else left  # noqa
        right = right.values if convert_B == True else right  # noqa

        return numpy_like.array_equal(left, right)