<s> import datetime <EOL> import six <EOL> from ibis . common import IbisError , RelationError <EOL> import ibis . common as com <EOL> import ibis . compat as compat <EOL> import ibis . config as config <EOL> import ibis . util as util <EOL> class Parameter ( object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class Expr ( object ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def __init__ ( self , arg ) : <EOL> self . _arg = arg <EOL> def __repr__ ( self ) : <EOL> if config . options . interactive : <EOL> try : <EOL> result = self . execute ( ) <EOL> return repr ( result ) <EOL> except com . TranslationError as e : <EOL> output = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( e . args [ <NUM_LIT:0> ] , self . _repr ( ) ) ) <EOL> return output <EOL> else : <EOL> return self . _repr ( ) <EOL> def _repr ( self , memo = None ) : <EOL> from ibis . expr . format import ExprFormatter <EOL> return ExprFormatter ( self ) . get_result ( ) <EOL> def pipe ( self , f , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( f , tuple ) : <EOL> f , data_keyword = f <EOL> kwargs = kwargs . copy ( ) <EOL> kwargs [ data_keyword ] = self <EOL> return f ( * args , ** kwargs ) <EOL> else : <EOL> return f ( self , * args , ** kwargs ) <EOL> __call__ = pipe <EOL> def op ( self ) : <EOL> return self . _arg <EOL> @ property <EOL> def _factory ( self ) : <EOL> def factory ( arg , name = None ) : <EOL> return type ( self ) ( arg , name = name ) <EOL> return factory <EOL> def _can_implicit_cast ( self , arg ) : <EOL> return False <EOL> def execute ( self , limit = '<STR_LIT:default>' , async = False ) : <EOL> """<STR_LIT>""" <EOL> from ibis . client import execute <EOL> return execute ( self , limit = limit , async = async ) <EOL> def compile ( self , limit = None ) : <EOL> """<STR_LIT>""" <EOL> from ibis . client import compile <EOL> return compile ( self , limit = limit ) <EOL> def verify ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . compile ( ) <EOL> return True <EOL> except : <EOL> return False <EOL> def equals ( self , other ) : <EOL> if type ( self ) != type ( other ) : <EOL> return False <EOL> return self . _arg . equals ( other . _arg ) <EOL> def _can_compare ( self , other ) : <EOL> return False <EOL> def _root_tables ( self ) : <EOL> return self . op ( ) . root_tables ( ) <EOL> def _get_unbound_tables ( self ) : <EOL> pass <EOL> def _safe_repr ( x , memo = None ) : <EOL> return x . _repr ( memo = memo ) if isinstance ( x , ( Expr , Node ) ) else repr ( x ) <EOL> class Node ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , args ) : <EOL> self . args = args <EOL> def __repr__ ( self ) : <EOL> return self . _repr ( ) <EOL> def _repr ( self , memo = None ) : <EOL> opname = type ( self ) . __name__ <EOL> pprint_args = [ ] <EOL> memo = memo or { } <EOL> if id ( self ) in memo : <EOL> return memo [ id ( self ) ] <EOL> def _pp ( x ) : <EOL> if isinstance ( x , Expr ) : <EOL> key = id ( x . op ( ) ) <EOL> else : <EOL> key = id ( x ) <EOL> if key in memo : <EOL> return memo [ key ] <EOL> result = _safe_repr ( x , memo = memo ) <EOL> memo [ key ] = result <EOL> return result <EOL> for x in self . args : <EOL> if isinstance ( x , ( tuple , list ) ) : <EOL> pp = repr ( [ _pp ( y ) for y in x ] ) <EOL> else : <EOL> pp = _pp ( x ) <EOL> pprint_args . append ( pp ) <EOL> return '<STR_LIT>' % ( opname , '<STR_LIT:U+002CU+0020>' . join ( pprint_args ) ) <EOL> def blocks ( self ) : <EOL> return False <EOL> def flat_args ( self ) : <EOL> for arg in self . args : <EOL> if isinstance ( arg , ( tuple , list ) ) : <EOL> for x in arg : <EOL> yield x <EOL> else : <EOL> yield arg <EOL> def equals ( self , other ) : <EOL> if type ( self ) != type ( other ) : <EOL> return False <EOL> if len ( self . args ) != len ( other . args ) : <EOL> return False <EOL> for left , right in zip ( self . args , other . args ) : <EOL> if not all_equal ( left , right ) : <EOL> return False <EOL> return True <EOL> def is_ancestor ( self , other ) : <EOL> if isinstance ( other , Expr ) : <EOL> other = other . op ( ) <EOL> return self . equals ( other ) <EOL> def to_expr ( self ) : <EOL> klass = self . output_type ( ) <EOL> return klass ( self ) <EOL> def output_type ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def all_equal ( left , right ) : <EOL> if isinstance ( left , list ) : <EOL> if not isinstance ( right , list ) : <EOL> return False <EOL> for a , b in zip ( left , right ) : <EOL> if not all_equal ( a , b ) : <EOL> return False <EOL> return True <EOL> if hasattr ( left , '<STR_LIT>' ) : <EOL> return left . equals ( right ) <EOL> else : <EOL> return left == right <EOL> return True <EOL> class ValueNode ( Node ) : <EOL> def __init__ ( self , * args ) : <EOL> args = self . _validate_args ( args ) <EOL> Node . __init__ ( self , args ) <EOL> def _validate_args ( self , args ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> return args <EOL> return self . input_type . validate ( args ) <EOL> def root_tables ( self ) : <EOL> exprs = [ arg for arg in self . args if isinstance ( arg , Expr ) ] <EOL> return distinct_roots ( * exprs ) <EOL> def resolve_name ( self ) : <EOL> raise com . ExpressionError ( '<STR_LIT>' % repr ( self ) ) <EOL> class TableColumn ( ValueNode ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , table_expr ) : <EOL> Node . __init__ ( self , [ name , table_expr ] ) <EOL> if name not in table_expr . schema ( ) : <EOL> raise KeyError ( "<STR_LIT>" . format ( name ) ) <EOL> self . name = name <EOL> self . table = table_expr <EOL> def parent ( self ) : <EOL> return self . table <EOL> def resolve_name ( self ) : <EOL> return self . name <EOL> def root_tables ( self ) : <EOL> return self . table . _root_tables ( ) <EOL> def to_expr ( self ) : <EOL> ctype = self . table . _get_type ( self . name ) <EOL> klass = ctype . array_type ( ) <EOL> return klass ( self , name = self . name ) <EOL> class ExpressionList ( Node ) : <EOL> def __init__ ( self , exprs ) : <EOL> exprs = [ as_value_expr ( x ) for x in exprs ] <EOL> Node . __init__ ( self , exprs ) <EOL> def root_tables ( self ) : <EOL> return distinct_roots ( * self . args ) <EOL> def output_type ( self ) : <EOL> return ExprList <EOL> class ExprList ( Expr ) : <EOL> def exprs ( self ) : <EOL> return self . op ( ) . args <EOL> def names ( self ) : <EOL> return [ x . get_name ( ) for x in self . exprs ( ) ] <EOL> def rename ( self , f ) : <EOL> new_exprs = [ x . name ( f ( x . get_name ( ) ) ) for x in self . exprs ( ) ] <EOL> return ExpressionList ( new_exprs ) . to_expr ( ) <EOL> def prefix ( self , value ) : <EOL> return self . rename ( lambda x : value + x ) <EOL> def suffix ( self , value ) : <EOL> return self . rename ( lambda x : x + value ) <EOL> def concat ( self , * others ) : <EOL> """<STR_LIT>""" <EOL> exprs = list ( self . exprs ( ) ) <EOL> for o in others : <EOL> if not isinstance ( o , ExprList ) : <EOL> raise TypeError ( o ) <EOL> exprs . extend ( o . exprs ( ) ) <EOL> return ExpressionList ( exprs ) . to_expr ( ) <EOL> class Literal ( ValueNode ) : <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % repr ( self . value ) <EOL> @ property <EOL> def args ( self ) : <EOL> return [ self . value ] <EOL> def equals ( self , other ) : <EOL> if not isinstance ( other , Literal ) : <EOL> return False <EOL> return ( isinstance ( other . value , type ( self . value ) ) and <EOL> self . value == other . value ) <EOL> def output_type ( self ) : <EOL> import ibis . expr . rules as rules <EOL> if isinstance ( self . value , bool ) : <EOL> klass = BooleanScalar <EOL> elif isinstance ( self . value , compat . integer_types ) : <EOL> int_type = rules . int_literal_class ( self . value ) <EOL> klass = int_type . scalar_type ( ) <EOL> elif isinstance ( self . value , float ) : <EOL> klass = DoubleScalar <EOL> elif isinstance ( self . value , six . string_types ) : <EOL> klass = StringScalar <EOL> elif isinstance ( self . value , datetime . datetime ) : <EOL> klass = TimestampScalar <EOL> else : <EOL> raise com . InputTypeError ( self . value ) <EOL> return klass <EOL> def root_tables ( self ) : <EOL> return [ ] <EOL> def distinct_roots ( * args ) : <EOL> all_roots = [ ] <EOL> for arg in args : <EOL> all_roots . extend ( arg . _root_tables ( ) ) <EOL> return util . unique_by_key ( all_roots , id ) <EOL> class ValueExpr ( Expr ) : <EOL> """<STR_LIT>""" <EOL> _implicit_casts = set ( ) <EOL> def __init__ ( self , arg , name = None ) : <EOL> Expr . __init__ ( self , arg ) <EOL> self . _name = name <EOL> def equals ( self , other ) : <EOL> if not isinstance ( other , ValueExpr ) : <EOL> return False <EOL> if self . _name != other . _name : <EOL> return False <EOL> return Expr . equals ( self , other ) <EOL> def type ( self ) : <EOL> import ibis . expr . datatypes as dt <EOL> return dt . _primitive_types [ self . _typename ] <EOL> def _base_type ( self ) : <EOL> return self . type ( ) <EOL> def _can_cast_implicit ( self , typename ) : <EOL> from ibis . expr . rules import ImplicitCast <EOL> rule = ImplicitCast ( self . type ( ) , self . _implicit_casts ) <EOL> return rule . can_cast ( typename ) <EOL> def get_name ( self ) : <EOL> if self . _name is not None : <EOL> return self . _name <EOL> return self . op ( ) . resolve_name ( ) <EOL> def name ( self , name ) : <EOL> return self . _factory ( self . _arg , name = name ) <EOL> class ScalarExpr ( ValueExpr ) : <EOL> pass <EOL> class ArrayExpr ( ValueExpr ) : <EOL> def parent ( self ) : <EOL> return self . _arg <EOL> def to_projection ( self ) : <EOL> """<STR_LIT>""" <EOL> roots = self . _root_tables ( ) <EOL> if len ( roots ) > <NUM_LIT:1> : <EOL> raise RelationError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> table = TableExpr ( roots [ <NUM_LIT:0> ] ) <EOL> return table . projection ( [ self ] ) <EOL> class AnalyticExpr ( Expr ) : <EOL> @ property <EOL> def _factory ( self ) : <EOL> def factory ( arg ) : <EOL> return type ( self ) ( arg ) <EOL> return factory <EOL> def type ( self ) : <EOL> return '<STR_LIT>' <EOL> class TableExpr ( Expr ) : <EOL> @ property <EOL> def _factory ( self ) : <EOL> def factory ( arg ) : <EOL> return TableExpr ( arg ) <EOL> return factory <EOL> def _is_valid ( self , exprs ) : <EOL> try : <EOL> self . _assert_valid ( util . promote_list ( exprs ) ) <EOL> return True <EOL> except : <EOL> return False <EOL> def _assert_valid ( self , exprs ) : <EOL> from ibis . expr . analysis import ExprValidator <EOL> ExprValidator ( [ self ] ) . validate_all ( exprs ) <EOL> def __contains__ ( self , name ) : <EOL> return name in self . schema ( ) <EOL> def __getitem__ ( self , what ) : <EOL> if isinstance ( what , six . string_types ) : <EOL> return self . get_column ( what ) <EOL> if isinstance ( what , slice ) : <EOL> step = what . step <EOL> if step is not None and step != <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> start = what . start or <NUM_LIT:0> <EOL> stop = what . stop <EOL> if stop is None or stop < <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if start < <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return self . limit ( stop - start , offset = start ) <EOL> what = bind_expr ( self , what ) <EOL> if isinstance ( what , AnalyticExpr ) : <EOL> what = what . _table_getitem ( ) <EOL> if isinstance ( what , ( list , tuple , TableExpr ) ) : <EOL> return self . projection ( what ) <EOL> elif isinstance ( what , BooleanArray ) : <EOL> return self . filter ( [ what ] ) <EOL> elif isinstance ( what , ArrayExpr ) : <EOL> return self . projection ( what ) <EOL> else : <EOL> raise NotImplementedError <EOL> def __len__ ( self ) : <EOL> raise com . ExpressionError ( '<STR_LIT>' ) <EOL> def __getattr__ ( self , key ) : <EOL> try : <EOL> return object . __getattribute__ ( self , key ) <EOL> except AttributeError : <EOL> if not self . _is_materialized ( ) or key not in self . schema ( ) : <EOL> raise <EOL> return self . get_column ( key ) <EOL> def __dir__ ( self ) : <EOL> attrs = dir ( type ( self ) ) <EOL> if self . _is_materialized ( ) : <EOL> attrs = list ( sorted ( set ( attrs + self . schema ( ) . names ) ) ) <EOL> return attrs <EOL> def _resolve ( self , exprs ) : <EOL> exprs = util . promote_list ( exprs ) <EOL> out_exprs = [ ] <EOL> for expr in exprs : <EOL> expr = self . _ensure_expr ( expr ) <EOL> out_exprs . append ( expr ) <EOL> return out_exprs <EOL> def _ensure_expr ( self , expr ) : <EOL> if isinstance ( expr , six . string_types ) : <EOL> return self [ expr ] <EOL> elif not isinstance ( expr , Expr ) : <EOL> return expr ( self ) <EOL> else : <EOL> return expr <EOL> def _get_type ( self , name ) : <EOL> return self . _arg . get_type ( name ) <EOL> def get_columns ( self , iterable ) : <EOL> """<STR_LIT>""" <EOL> return [ self . get_column ( x ) for x in iterable ] <EOL> def get_column ( self , name ) : <EOL> """<STR_LIT>""" <EOL> ref = TableColumn ( name , self ) <EOL> return ref . to_expr ( ) <EOL> @ property <EOL> def columns ( self ) : <EOL> return self . schema ( ) . names <EOL> def schema ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _is_materialized ( ) : <EOL> raise IbisError ( '<STR_LIT>' ) <EOL> return self . op ( ) . get_schema ( ) <EOL> def _is_materialized ( self ) : <EOL> return self . op ( ) . has_schema ( ) <EOL> def add_column ( self , expr , name = None ) : <EOL> """<STR_LIT>""" <EOL> expr = self . _ensure_expr ( expr ) <EOL> if not isinstance ( expr , ArrayExpr ) : <EOL> raise com . InputTypeError ( '<STR_LIT>' ) <EOL> if name is not None : <EOL> expr = expr . name ( name ) <EOL> return self . projection ( [ self , expr ] ) <EOL> def group_by ( self , by ) : <EOL> """<STR_LIT>""" <EOL> from ibis . expr . groupby import GroupedTableExpr <EOL> return GroupedTableExpr ( self , by ) <EOL> class AnyValue ( ValueExpr ) : <EOL> _typename = '<STR_LIT>' <EOL> class NullValue ( AnyValue ) : <EOL> _typename = '<STR_LIT:null>' <EOL> def _can_cast_implicit ( self , typename ) : <EOL> return True <EOL> class NumericValue ( AnyValue ) : <EOL> def _can_compare ( self , other ) : <EOL> return isinstance ( other , NumericValue ) <EOL> class IntegerValue ( NumericValue ) : <EOL> pass <EOL> class BooleanValue ( NumericValue ) : <EOL> _typename = '<STR_LIT>' <EOL> class Int8Value ( IntegerValue ) : <EOL> _typename = '<STR_LIT>' <EOL> _implicit_casts = set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:float>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> class Int16Value ( IntegerValue ) : <EOL> _typename = '<STR_LIT>' <EOL> _implicit_casts = set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:float>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Int32Value ( IntegerValue ) : <EOL> _typename = '<STR_LIT>' <EOL> _implicit_casts = set ( [ '<STR_LIT>' , '<STR_LIT:float>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Int64Value ( IntegerValue ) : <EOL> _typename = '<STR_LIT>' <EOL> _implicit_casts = set ( [ '<STR_LIT:float>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class FloatingValue ( NumericValue ) : <EOL> pass <EOL> class FloatValue ( FloatingValue ) : <EOL> _typename = '<STR_LIT:float>' <EOL> _implicit_casts = set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class DoubleValue ( FloatingValue ) : <EOL> _typename = '<STR_LIT>' <EOL> _implicit_casts = set ( [ '<STR_LIT>' ] ) <EOL> class StringValue ( AnyValue ) : <EOL> _typename = '<STR_LIT:string>' <EOL> def _can_compare ( self , other ) : <EOL> return isinstance ( other , StringValue ) <EOL> class DecimalValue ( NumericValue ) : <EOL> _typename = '<STR_LIT>' <EOL> _implicit_casts = set ( [ '<STR_LIT:float>' , '<STR_LIT>' ] ) <EOL> def __init__ ( self , meta ) : <EOL> self . meta = meta <EOL> self . _precision = meta . precision <EOL> self . _scale = meta . scale <EOL> def type ( self ) : <EOL> from ibis . expr . datatypes import Decimal <EOL> return Decimal ( self . _precision , self . _scale ) <EOL> def _base_type ( self ) : <EOL> return '<STR_LIT>' <EOL> @ classmethod <EOL> def _make_constructor ( cls , meta ) : <EOL> def constructor ( arg , name = None ) : <EOL> return cls ( arg , meta , name = name ) <EOL> return constructor <EOL> class TimestampValue ( AnyValue ) : <EOL> _typename = '<STR_LIT>' <EOL> def _can_implicit_cast ( self , arg ) : <EOL> op = arg . op ( ) <EOL> if isinstance ( op , Literal ) : <EOL> try : <EOL> import pandas as pd <EOL> pd . Timestamp ( op . value ) <EOL> return True <EOL> except ValueError : <EOL> return False <EOL> return False <EOL> def _can_compare ( self , other ) : <EOL> return isinstance ( other , TimestampValue ) <EOL> def _implicit_cast ( self , arg ) : <EOL> op = arg . op ( ) <EOL> return TimestampScalar ( op ) <EOL> class NumericArray ( ArrayExpr , NumericValue ) : <EOL> pass <EOL> class NullScalar ( NullValue , ScalarExpr ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class BooleanScalar ( ScalarExpr , BooleanValue ) : <EOL> pass <EOL> class BooleanArray ( NumericArray , BooleanValue ) : <EOL> pass <EOL> class Int8Scalar ( ScalarExpr , Int8Value ) : <EOL> pass <EOL> class Int8Array ( NumericArray , Int8Value ) : <EOL> pass <EOL> class Int16Scalar ( ScalarExpr , Int16Value ) : <EOL> pass <EOL> class Int16Array ( NumericArray , Int16Value ) : <EOL> pass <EOL> class Int32Scalar ( ScalarExpr , Int32Value ) : <EOL> pass <EOL> class Int32Array ( NumericArray , Int32Value ) : <EOL> pass <EOL> class Int64Scalar ( ScalarExpr , Int64Value ) : <EOL> pass <EOL> class Int64Array ( NumericArray , Int64Value ) : <EOL> pass <EOL> class FloatScalar ( ScalarExpr , FloatValue ) : <EOL> pass <EOL> class FloatArray ( NumericArray , FloatValue ) : <EOL> pass <EOL> class DoubleScalar ( ScalarExpr , DoubleValue ) : <EOL> pass <EOL> class DoubleArray ( NumericArray , DoubleValue ) : <EOL> pass <EOL> class StringScalar ( ScalarExpr , StringValue ) : <EOL> pass <EOL> class StringArray ( ArrayExpr , StringValue ) : <EOL> pass <EOL> class TimestampScalar ( ScalarExpr , TimestampValue ) : <EOL> pass <EOL> class TimestampArray ( ArrayExpr , TimestampValue ) : <EOL> pass <EOL> class DecimalScalar ( DecimalValue , ScalarExpr ) : <EOL> def __init__ ( self , arg , meta , name = None ) : <EOL> DecimalValue . __init__ ( self , meta ) <EOL> ScalarExpr . __init__ ( self , arg , name = name ) <EOL> @ property <EOL> def _factory ( self ) : <EOL> def factory ( arg , name = None ) : <EOL> return DecimalScalar ( arg , self . meta , name = name ) <EOL> return factory <EOL> class DecimalArray ( DecimalValue , NumericArray ) : <EOL> def __init__ ( self , arg , meta , name = None ) : <EOL> DecimalValue . __init__ ( self , meta ) <EOL> ArrayExpr . __init__ ( self , arg , name = name ) <EOL> @ property <EOL> def _factory ( self ) : <EOL> def factory ( arg , name = None ) : <EOL> return DecimalArray ( arg , self . meta , name = name ) <EOL> return factory <EOL> class CategoryValue ( AnyValue ) : <EOL> """<STR_LIT>""" <EOL> _typename = '<STR_LIT>' <EOL> _implicit_casts = Int16Value . _implicit_casts <EOL> def __init__ ( self , meta ) : <EOL> self . meta = meta <EOL> def type ( self ) : <EOL> return self . meta <EOL> def _base_type ( self ) : <EOL> return '<STR_LIT>' <EOL> def _can_compare ( self , other ) : <EOL> return isinstance ( other , IntegerValue ) <EOL> class CategoryScalar ( CategoryValue , ScalarExpr ) : <EOL> def __init__ ( self , arg , meta , name = None ) : <EOL> CategoryValue . __init__ ( self , meta ) <EOL> ScalarExpr . __init__ ( self , arg , name = name ) <EOL> @ property <EOL> def _factory ( self ) : <EOL> def factory ( arg , name = None ) : <EOL> return CategoryScalar ( arg , self . meta , name = name ) <EOL> return factory <EOL> class CategoryArray ( CategoryValue , ArrayExpr ) : <EOL> def __init__ ( self , arg , meta , name = None ) : <EOL> CategoryValue . __init__ ( self , meta ) <EOL> ArrayExpr . __init__ ( self , arg , name = name ) <EOL> @ property <EOL> def _factory ( self ) : <EOL> def factory ( arg , name = None ) : <EOL> return CategoryArray ( arg , self . meta , name = name ) <EOL> return factory <EOL> class UnnamedMarker ( object ) : <EOL> pass <EOL> unnamed = UnnamedMarker ( ) <EOL> def as_value_expr ( val ) : <EOL> import pandas as pd <EOL> if not isinstance ( val , Expr ) : <EOL> if isinstance ( val , ( tuple , list ) ) : <EOL> val = sequence ( val ) <EOL> elif isinstance ( val , pd . Series ) : <EOL> val = sequence ( list ( val ) ) <EOL> else : <EOL> val = literal ( val ) <EOL> return val <EOL> def literal ( value ) : <EOL> """<STR_LIT>""" <EOL> if value is None or value is null : <EOL> return null ( ) <EOL> else : <EOL> return Literal ( value ) . to_expr ( ) <EOL> _NULL = None <EOL> def null ( ) : <EOL> """<STR_LIT>""" <EOL> global _NULL <EOL> if _NULL is None : <EOL> _NULL = NullScalar ( NullLiteral ( ) ) <EOL> return _NULL <EOL> def sequence ( values ) : <EOL> """<STR_LIT>""" <EOL> return ValueList ( values ) . to_expr ( ) <EOL> class NullLiteral ( ValueNode ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> pass <EOL> @ property <EOL> def args ( self ) : <EOL> return [ None ] <EOL> def equals ( self , other ) : <EOL> return isinstance ( other , NullLiteral ) <EOL> def output_type ( self ) : <EOL> return NullScalar <EOL> def root_tables ( self ) : <EOL> return [ ] <EOL> class ListExpr ( ArrayExpr , AnyValue ) : <EOL> pass <EOL> class SortExpr ( Expr ) : <EOL> pass <EOL> class ValueList ( ValueNode ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , args ) : <EOL> self . values = [ as_value_expr ( x ) for x in args ] <EOL> ValueNode . __init__ ( self , self . values ) <EOL> def root_tables ( self ) : <EOL> return distinct_roots ( * self . values ) <EOL> def to_expr ( self ) : <EOL> return ListExpr ( self ) <EOL> def bind_expr ( table , expr ) : <EOL> if isinstance ( expr , ( list , tuple ) ) : <EOL> return [ bind_expr ( table , x ) for x in expr ] <EOL> return table . _ensure_expr ( expr ) <EOL> def find_base_table ( expr ) : <EOL> if isinstance ( expr , TableExpr ) : <EOL> return expr <EOL> for arg in expr . op ( ) . flat_args ( ) : <EOL> if isinstance ( arg , Expr ) : <EOL> r = find_base_table ( arg ) <EOL> if isinstance ( r , TableExpr ) : <EOL> return r </s>
