Ejemplo n.º 1
0
            def _series_binop_none_indexes_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)

                if (len(self._data) == len(other._data)):
                    result_data = numpy_like.astype(self._data, numpy.float64)
                    result_data = result_data + other._data
                    return pandas.Series(result_data)
                else:
                    left_size, right_size = len(self._data), len(other._data)
                    min_data_size = min(left_size, right_size)
                    max_data_size = max(left_size, right_size)
                    result_data = numpy.empty(max_data_size,
                                              dtype=numpy.float64)
                    _fill_value = numpy.nan if fill_value_is_none == True else fill_value  # noqa
                    if (left_size == min_data_size):
                        result_data[:min_data_size] = self._data
                        for i in range(min_data_size, len(result_data)):
                            result_data[i] = _fill_value
                        result_data = result_data + other._data
                    else:
                        result_data[:min_data_size] = other._data
                        for i in range(min_data_size, len(result_data)):
                            result_data[i] = _fill_value
                        result_data = self._data + result_data

                    return pandas.Series(result_data)
Ejemplo n.º 2
0
            def _series_binop_common_impl(self, other, level=None, fill_value=None, axis=0):
                left_index, right_index = self.index, other.index
                _fill_value = numpy.nan if fill_value_is_none == True else fill_value  # noqa
                if not (fill_value is None or numpy.isnan(fill_value)):
                    numpy_like.fillna(self._data, inplace=True, value=fill_value)
                    numpy_like.fillna(other._data, inplace=True, value=fill_value)
                # check if indexes are equal and series don't have to be aligned
                if sdc_check_indexes_equal(left_index, right_index):
                    result_data = numpy.empty(len(self._data), dtype=numpy.float64)
                    result_data[:] = self._data + other._data

                    if none_or_numeric_indexes == True:  # noqa
                        result_index = numpy_like.astype(left_index, numba_index_common_dtype)
                    else:
                        result_index = self._index

                    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)
                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)
Ejemplo n.º 3
0
            def _series_operator_binop_common_impl(self, other):
                left_index, right_index = self.index, other.index

                # check if indexes are equal and series don't have to be aligned
                if sdc_check_indexes_equal(left_index, right_index):
                    result_data = numpy.empty(len(self._data),
                                              dtype=numpy.float64)
                    result_data[:] = self._data + other._data

                    if none_or_numeric_indexes == True:  # noqa
                        result_index = astype(left_index,
                                              numba_index_common_dtype)
                    else:
                        result_index = self._index

                    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)
                for i in numba.prange(result_size):
                    left_pos, right_pos = left_indexer[i], right_indexer[i]
                    left_values[i] = self._data[
                        left_pos] if left_pos != -1 else numpy.nan
                    right_values[i] = other._data[
                        right_pos] if right_pos != -1 else numpy.nan

                result_data = left_values + right_values
                return pandas.Series(result_data, joined_index)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
            def _series_operator_comp_binop_common_impl(self, other):
                left_index, right_index = self.index, other.index

                if sdc_check_indexes_equal(left_index, right_index):
                    if none_or_numeric_indexes == True:  # noqa
                        new_index = astype(left_index,
                                           numba_index_common_dtype)
                    else:
                        new_index = self._index
                    return pandas.Series(self._data < other._data, new_index)
                else:
                    raise ValueError(
                        "Can only compare identically-labeled Series objects")
Ejemplo n.º 6
0
    def sdc_unify_index_types_impl(left, right):
        if index_dtypes_match == True:  # noqa
            return left
        else:
            if is_left_index_cached == True:  # noqa
                index_data = left.values if is_left_index_array == False else left  # noqa
            elif is_right_index_cached == True:  # noqa
                index_data = right.values if is_right_index_array == False else right  # noqa
            else:
                # using numpy_like.astype but not index.astype since latter works differently
                index_data = numpy_like.astype(left, numba_index_common_dtype)

        return fix_df_index(index_data)
Ejemplo n.º 7
0
            def _series_comp_binop_common_impl(self, other, level=None, fill_value=None, axis=0):
                if not (fill_value is None or numpy.isnan(fill_value)):
                    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 sdc_check_indexes_equal(left_index, right_index):
                    if none_or_numeric_indexes == True:  # noqa
                        new_index = numpy_like.astype(left_index, numba_index_common_dtype)
                    else:
                        new_index = self._index
                    return pandas.Series(self._data < other._data,
                                         new_index)
                else:
                    raise ValueError("Can only compare identically-labeled Series objects")
Ejemplo n.º 8
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)
Ejemplo n.º 9
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")
Ejemplo n.º 10
0
    def pd_int64_index_ctor_impl(data, dtype=None, copy=False, name=None):

        if not (dtype is None
                or dtype_is_numpy_signed_int
                or dtype_is_unicode_str and dtype in ('int8', 'int16', 'int32', 'int64')):
            raise ValueError("Incorrect `dtype` passed: expected signed integer")

        if is_data_array == True:  # noqa
            _data = data
        elif is_data_index == True:  # noqa
            _data = data.values
        else:
            _data = fix_df_index(data)._data

        if data_dtype_is_int64 == False:  # noqa
            _data = numpy_like.astype(_data, dtype=types.int64)
        else:
            if copy:
                _data = np.copy(_data)
        return init_int64_index(_data, name)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
            def _series_operator_binop_none_indexes_impl(self, other):

                if (len(self._data) == len(other._data)):
                    result_data = astype(self._data, numpy.float64)
                    result_data = result_data + other._data
                    return pandas.Series(result_data)
                else:
                    left_size, right_size = len(self._data), len(other._data)
                    min_data_size = min(left_size, right_size)
                    max_data_size = max(left_size, right_size)
                    result_data = numpy.empty(max_data_size,
                                              dtype=numpy.float64)
                    if (left_size == min_data_size):
                        result_data[:min_data_size] = self._data
                        result_data[min_data_size:] = numpy.nan
                        result_data = result_data + other._data
                    else:
                        result_data[:min_data_size] = other._data
                        result_data[min_data_size:] = numpy.nan
                        result_data = self._data + result_data

                    return pandas.Series(result_data)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def sdc_impl(a):
     return numpy_like.astype(a, str)
Ejemplo n.º 15
0
 def sdc_impl(a):
     return numpy_like.astype(a, np.int64)
Ejemplo n.º 16
0
 def sdc_impl(a):
     return numpy_like.astype(a, 'float64')
Ejemplo n.º 17
0
 def sdc_func(index):
     return astype(index, np.int64)