예제 #1
0
def adjust_context_window(op, timecontext: Optional[TimeContext], **kwargs):
    new_timecontexts = [
        timecontext for arg in op.inputs if is_computable_input(arg)
    ]

    if not timecontext:
        return new_timecontexts

    # adjust time context by preceding and following
    begin, end = timecontext
    result = [begin, end]
    preceding = op.window.preceding
    following = op.window.following
    if preceding is not None:
        if isinstance(preceding, ir.IntervalScalar):
            new_preceding = execute(preceding)
        else:
            new_preceding = preceding
        if new_preceding:
            result[0] = begin - new_preceding
    if following is not None:
        if isinstance(following, ir.IntervalScalar):
            new_following = execute(following)
        else:
            new_following = following
        if new_following:
            result[1] = end + new_following
    new_timecontexts = [
        result for arg in op.inputs if is_computable_input(arg)
    ]
    return new_timecontexts
예제 #2
0
파일: client.py 프로젝트: djv/ibis
class PandasClient(client.Client):

    dialect = None  # defined in ibis.pandas.api

    def __init__(self, dictionary):
        self.dictionary = dictionary

    def table(self, name, schema=None):
        df = self.dictionary[name]
        schema = sch.infer(df, schema=schema)
        return PandasTable(name, schema, self).to_expr()

    def execute(self, query, params=None, limit='default', async=False):
        from ibis.pandas.execution import execute

        if limit != 'default':
            raise ValueError(
                'limit parameter to execute is not yet implemented in the '
                'pandas backend')

        if async:
            raise ValueError(
                'async is not yet supported in the pandas backend')

        assert isinstance(query, ir.Expr)
        return execute(query, params=params)
예제 #3
0
def adjust_context_asof_join(
    op: Node, timecontext: TimeContext
) -> TimeContext:
    begin, end = timecontext

    if op.tolerance is not None:
        from ibis.pandas.execution import execute

        timedelta = execute(op.tolerance)
        return (begin - timedelta, end)

    return timecontext
예제 #4
0
def adjust_context_window(op: Node, timecontext: TimeContext) -> TimeContext:
    # adjust time context by preceding and following
    begin, end = timecontext

    preceding = op.window.preceding
    if preceding is not None:
        if isinstance(preceding, ir.IntervalScalar):
            from ibis.pandas.execution import execute

            preceding = execute(preceding)
        if preceding and not isinstance(preceding, (int, np.integer)):
            begin = begin - preceding

    following = op.window.following
    if following is not None:
        if isinstance(following, ir.IntervalScalar):
            from ibis.pandas.execution import execute

            following = execute(following)
        if following and not isinstance(following, (int, np.integer)):
            end = end + following

    return (begin, end)
예제 #5
0
def adjust_context_asof_join(op, timecontext: Optional[TimeContext], **kwargs):
    new_timecontexts = [
        timecontext for arg in op.inputs if is_computable_input(arg)
    ]

    if not timecontext:
        return new_timecontexts
    begin, end = timecontext
    tolerance = op.tolerance
    if tolerance is not None:
        timedelta = execute(tolerance)
        # only backwards and adjust begin time only
        new_begin = begin - timedelta
        new_end = end
    # right table is the second node in children
    new_timecontexts[1] = (new_begin, new_end)
    return new_timecontexts
예제 #6
0
def compile_literal(t, expr, scope, timecontext, raw=False, **kwargs):
    """ If raw is True, don't wrap the result with F.lit()
    """
    value = expr.op().value
    dtype = expr.op().dtype

    if raw:
        return value

    if isinstance(dtype, dtypes.Interval):
        # execute returns a Timedelta and value is nanoseconds
        return execute(expr).value

    if isinstance(value, collections.abc.Set):
        # Don't wrap set with F.lit
        if isinstance(value, frozenset):
            # Spark doens't like frozenset
            return set(value)
        else:
            return value
    elif isinstance(value, list):
        return F.array(*[F.lit(v) for v in value])
    else:
        return F.lit(expr.op().value)