Skip to content

Commit

Permalink
Merge remote-tracking branch 'ibis-project/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed May 15, 2018
2 parents 5a7aa1f + 6f90d2f commit 3ec3ea6
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 94 deletions.
7 changes: 7 additions & 0 deletions ibis/bigquery/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,10 @@ def test_multiple_project_queries_execute(client):
result = join.execute()
assert list(result.columns) == ['title']
assert len(result) == 5


def test_large_timestamp(client):
huge_timestamp = datetime(year=4567, month=1, day=1)
expr = ibis.timestamp('4567-01-01 00:00:00')
result = client.execute(expr)
assert result == huge_timestamp
11 changes: 9 additions & 2 deletions ibis/bigquery/udf/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,17 @@ def visit_ListComp(self, node):
'Only single loop comprehensions are allowed'
)

names = find_names(node.elt)
names = find_names(generator.target)
argslist = [ast.arg(arg=name.id, annotation=None) for name in names]
if len(names) <= 1:
signature = ast.arguments(args=argslist)
signature = ast.arguments(
args=argslist,
vararg=None,
kwonlyargs=[],
kw_defaults=[],
kwarg=None,
defaults=[]
)
else:
signature = ast.List(elts=argslist, ctx=ast.Load())

Expand Down
11 changes: 11 additions & 0 deletions ibis/bigquery/udf/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,14 @@ def f(*args):
}"""
js = compile(f)
assert js == expected


def test_missing_vararg():
def my_range(n):
return [1 for x in [n]]
js = compile(my_range)
expected = """\
function my_range(n) {
return [n].map(((x) => 1));
}"""
assert js == expected
52 changes: 22 additions & 30 deletions ibis/expr/api.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
# Copyright 2015 Cloudera Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function

import collections
import datetime
import functools
import operator
import warnings

import six
import toolz
import warnings
import operator
import datetime

import functools
import collections
import dateutil.parser

import pandas as pd

import ibis.util as util
import ibis.common as com
Expand Down Expand Up @@ -175,8 +165,10 @@ def timestamp(value):
result : TimestampScalar
"""
if isinstance(value, six.string_types):
from pandas import Timestamp
value = Timestamp(value)
try:
value = pd.Timestamp(value)
except pd.errors.OutOfBoundsDatetime:
value = dateutil.parser.parse(value)
if isinstance(value, six.integer_types):
warnings.warn(
'Integer values for timestamp literals are deprecated in 0.11.0 '
Expand Down Expand Up @@ -2501,8 +2493,7 @@ def _time_sub(left, right):


def join(left, right, predicates=(), how='inner'):
"""
Perform a relational join between two tables. Does not resolve resulting
"""Perform a relational join between two tables. Does not resolve resulting
table schema.
Parameters
Expand All @@ -2521,7 +2512,7 @@ def join(left, right, predicates=(), how='inner'):
Returns
-------
joined : TableExpr
Note, schema is not materialized yet
Note that the schema is not materialized yet
"""
klass = _join_classes[how.lower()]
if isinstance(predicates, Expr):
Expand All @@ -2531,9 +2522,8 @@ def join(left, right, predicates=(), how='inner'):
return ir.TableExpr(op)


def asof_join(left, right, predicates=(), by=()):
"""
Perform an asof join between two tables. Similar to a left join
def asof_join(left, right, predicates=(), by=(), tolerance=None):
"""Perform an asof join between two tables. Similar to a left join
except that the match is done on nearest key rather than equal keys.
Optionally, match keys with 'by' before joining with predicates.
Expand All @@ -2544,14 +2534,16 @@ def asof_join(left, right, predicates=(), by=()):
right : TableExpr
predicates : join expression(s)
by : string
column to group by before joining
column to group by before joining
tolerance : interval
Amount of time to look behind when joining
Returns
-------
joined : TableExpr
Note, schema is not materialized yet
Note that the schema is not materialized yet
"""
return ops.AsOfJoin(left, right, predicates, by).to_expr()
return ops.AsOfJoin(left, right, predicates, by, tolerance).to_expr()


def cross_join(*tables, **kwargs):
Expand Down
4 changes: 3 additions & 1 deletion ibis/expr/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,10 +1642,12 @@ class AsOfJoin(Join):
right = Arg(rlz.noop)
predicates = Arg(rlz.noop)
by = Arg(rlz.noop, default=None)
tolerance = Arg(rlz.interval(), default=None)

def __init__(self, left, right, predicates, by):
def __init__(self, left, right, predicates, by, tolerance):
super(AsOfJoin, self).__init__(left, right, predicates)
self.by = _clean_join_predicates(self.left, self.right, by)
self.tolerance = tolerance


class Union(TableNode, HasSchema):
Expand Down
7 changes: 7 additions & 0 deletions ibis/expr/tests/test_value_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,3 +1302,10 @@ def test_interval_negate(base_expr):
assert isinstance(expr.op(), ops.Negate)
assert expr.equals(expr2)
assert expr.equals(expr3)


def test_large_timestamp():
expr = ibis.timestamp('4567-02-03')
expected = datetime(year=4567, month=2, day=3)
result = expr.op().value
assert result == expected
Loading

0 comments on commit 3ec3ea6

Please sign in to comment.