Skip to content

Commit

Permalink
Refactores appointed on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed May 2, 2018
1 parent 32321c2 commit 71c9366
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 181 deletions.
20 changes: 9 additions & 11 deletions ibis/expr/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,14 @@ class Radians(UnaryOp):
class TrigonometricUnary(UnaryOp):
"""Trigonometric base unary"""
arg = Arg(rlz.numeric)
output_type = rlz.shape_like('arg', 'float')
output_type = rlz.shape_like('arg', dt.float64)


class TrigonometricBinary(BinaryOp):
"""Trigonometric base binary"""
left = Arg(rlz.numeric)
right = Arg(rlz.numeric)
output_type = rlz.shape_like('left', 'float')
output_type = rlz.shape_like('args', dt.float64)


class Acos(TrigonometricUnary):
Expand Down Expand Up @@ -859,10 +859,7 @@ class Variance(VarianceBase):


class Correlation(Reduction):
"""
coefficient of correlation of a set of number pairs.
"""
"""Coefficient of correlation of a set of number pairs."""
left = Arg(rlz.numeric)
right = Arg(rlz.numeric)
how = Arg(rlz.isin({'sample', 'pop'}), default=None)
Expand All @@ -877,6 +874,7 @@ def output_type(self):


class Covariance(Reduction):
"""Covariance of a set of number pairs."""
left = Arg(rlz.column(rlz.numeric))
right = Arg(rlz.column(rlz.numeric))
how = Arg(rlz.isin({'sample', 'pop'}), default=None)
Expand Down Expand Up @@ -2808,8 +2806,8 @@ class Distance(ValueOp):
Calculates distance in meters between two WGS-84 positions.
"""
from_lon = Arg(rlz.column(rlz.numeric))
from_lat = Arg(rlz.column(rlz.numeric))
to_lon = Arg(rlz.column(rlz.numeric))
to_lat = Arg(rlz.column(rlz.numeric))
output_type = rlz.shape_like('from_lon', dt.float)
from_lon = Arg(rlz.numeric)
from_lat = Arg(rlz.numeric)
to_lon = Arg(rlz.numeric)
to_lat = Arg(rlz.numeric)
output_type = rlz.shape_like('args', dt.float64)
111 changes: 0 additions & 111 deletions ibis/mapd/identifiers.py
Original file line number Diff line number Diff line change
@@ -1,114 +1,3 @@
"""
_identifiers = frozenset({
'add',
'aggregate',
'all',
'alter',
'and',
'as',
'asc',
'between',
'by',
'cached',
'case',
'cast',
'change',
'class',
'column',
'columns',
'comment',
'create',
'cross',
'data',
'database',
'databases',
'date',
'datetime',
'desc',
'describe',
'distinct',
'div',
'double',
'drop',
'else',
'end',
'escaped',
'exists',
'explain',
'external',
'fields',
'fileformat',
'first',
'float',
'format',
'from',
'full',
'function',
'functions',
'group',
'having',
'if',
'in',
'inner',
'inpath',
'insert',
'int',
'integer',
'intermediate',
'interval',
'into',
'is',
'join',
'last',
'left',
'like',
'limit',
'lines',
'load',
'location',
'metadata',
'not',
'null',
'offset',
'on',
'or',
'order',
'outer',
'partition',
'partitioned',
'partitions',
'real',
'refresh',
'regexp',
'rename',
'replace',
'returns',
'right',
'row',
'schema',
'schemas',
'select',
'set',
'show',
'stats',
'stored',
'string',
'symbol',
'table',
'tables',
'then',
'to',
'union',
'use',
'using',
'values',
'view',
'when',
'where',
'with'
})
"""

# https://www.mapd.com/docs/latest/mapd-core-guide/tables/
# https://www.mapd.com/docs/latest/mapd-core-guide/views/
# https://www.mapd.com/docs/latest/mapd-core-guide/data-definition/
Expand Down
60 changes: 1 addition & 59 deletions ibis/mapd/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
import ibis.expr.types as ir
import ibis.expr.operations as ops

_mapd_unit_names = {
'Y': 'YEAR',
'M': 'MONTH',
'D': 'DAY',
'W': 'WEEK',
'Q': 'QUARTER',
'h': 'HOUR',
'm': 'MINUTE',
's': 'SECOND',
}

_sql_type_names = {
'int8': 'smallint',
'int16': 'smallint',
Expand All @@ -39,45 +28,6 @@
}


def _add_method(dtype, klass, func_name):
"""
:param dtype:
:param klass:
:param func_name:
:return:
"""
def f(_klass):
"""
Return a lambda function that return to_expr() result from the
custom classes.
"""
def _f(*args, **kwargs):
return _klass(*args, **kwargs).to_expr()
return _f
# assign new function to the defined DataType
setattr(
dtype, func_name, f(klass)
)


def _add_methods(dtype, function_ops, forced=False):
"""
:param dtype:
:param function_ops: dict
:param forced:
:return:
"""
for klass in function_ops.keys():
# skip if the class is already in the ibis operations
if klass in ops.__dict__.values() and not forced:
continue
# assign new function to the defined DataType
func_name = _operation_registry[klass].__name__
_add_method(dtype, klass, func_name)


def _is_floating(*args):
for arg in args:
if isinstance(arg, ir.FloatingColumn):
Expand Down Expand Up @@ -437,10 +387,7 @@ def _timestamp_truncate(translator, expr):
op = expr.op()
arg, unit = op.args

if unit.upper() in [u.upper() for u in _mapd_unit_names.keys()]:
unit_ = _mapd_unit_names[unit].upper()
else:
raise ValueError('`{}` unit is not supported!'.format(unit))
unit_ = dt.Interval(unit=unit).resolution.upper()

# return _call_date_trunc(translator, converter, arg)
arg_ = translator.translate(arg)
Expand Down Expand Up @@ -502,11 +449,6 @@ def distance(translator, expr):
# classes

# MATH
class Log(ops.Ln):
"""
"""


class NumericTruncate(ops.NumericBinaryOp):
"""Truncates x to y decimal places"""
Expand Down

0 comments on commit 71c9366

Please sign in to comment.