예제 #1
0
파일: pd_series_ext.py 프로젝트: samaid/sdc
def type_sub(context):
    def typer(val1, val2):
        if is_dt64_series_typ(val1) and val2 == pandas_timestamp_type:
            return SeriesType(types.NPTimedelta('ns'))

        from hpat.hiframes.pd_index_ext import DatetimeIndexType
        if isinstance(val1,
                      DatetimeIndexType) and val2 == pandas_timestamp_type:
            from hpat.hiframes.pd_index_ext import TimedeltaIndexType
            return TimedeltaIndexType(False)

    return typer


type_callable('-')(type_sub)
type_callable(operator.sub)(type_sub)


@overload(pd.Series)
def pd_series_overload(data=None,
                       index=None,
                       dtype=None,
                       name=None,
                       copy=False,
                       fastpath=False):

    if index is not None:

        def hpat_pandas_series_index_ctor_impl(data=None,
                                               index=None,
예제 #2
0
    raise NotImplementedError


def type_func1_(context):
    def typer(x=None):
        if x in (None, types.none):
            # 0-arg or 1-arg with None
            return types.int32
        elif isinstance(x, types.Float):
            # 1-arg with float
            return x

    return typer


type_func1 = type_callable(func1)(type_func1_)


@lower_builtin(func1)
@lower_builtin(func1, types.none)
def func1_nullary(context, builder, sig, args):
    return context.get_constant(sig.return_type, 42)


@lower_builtin(func1, types.Float)
def func1_unary(context, builder, sig, args):
    def func1_impl(x):
        return math.sqrt(2 * x)

    return context.compile_internal(builder, func1_impl, sig, args)