# Path: bamboo/lib/datetools.py
# def now():
#     return datetime.now()
# 
# def parse_date_to_unix_time(date):
#     return timegm(date.utctimetuple())
# 
# def parse_str_to_unix_time(value):
#     return parse_date_to_unix_time(date_parse(value))
# 
# def safe_parse_date_to_unix_time(date):
#     if isinstance(date, datetime):
#         date = parse_date_to_unix_time(date)
# 
#     return date
# 
# Path: bamboo/lib/query_args.py
# class QueryArgs(object):
#     def __init__(self, query=None, select=None, distinct=None, limit=0,
#                  order_by=None, dataset=None):
#         """A holder for query arguments.
# 
#         :param query: An optional query.
#         :param select: An optional select to limit the fields in the dframe.
#         :param distinct: Return distinct entries for this field.
#         :param limit: Limit on the number of rows in the returned dframe.
#         :param order_by: Sort resulting rows according to a column value and
#             sign indicating ascending or descending.
# 
#         Example of `order_by`:
# 
#           - ``order_by='mycolumn'``
#           - ``order_by='-mycolumn'``
#         """
#         self.query = parse_dates_from_query(query, dataset)
#         self.select = select
#         self.distinct = distinct
#         self.limit = limit
#         self.order_by = parse_order_by(order_by)
# 
#     def encode(self, encoding, query):
#         """Encode query, order_by, and select given an encoding.
# 
#         The query will be combined with the existing query.
# 
#         :param encoding: A dict to encode the QueryArgs fields with.
#         :param query: An additional dict to combine with the existing query.
#         """
#         self.query = replace_keys(combine_dicts(self.query, query), encoding)
#         self.order_by = self.order_by and replace_keys(dict(self.order_by),
#                                                        encoding).items()
#         self.select = self.select and replace_keys(self.select, encoding)
# 
#     def __nonzero__(self):
#         return bool(self.query or self.select or self.distinct or self.limit
#                     or self.order_by)
# 
# Path: bamboo/lib/utils.py
# def parse_float(value, default=None):
#     return _parse_type(np.float64, value, default)


import operator
import numpy as np
from scipy.stats import percentileofscore
from bamboo.lib.datetools import now, parse_date_to_unix_time,\
    parse_str_to_unix_time, safe_parse_date_to_unix_time
from bamboo.lib.query_args import QueryArgs
from bamboo.lib.utils import parse_float
    """Base class for evaluation."""

    def __init__(self, tokens):
        self.tokens = tokens
        self.value = tokens[0]

    def operator_operands(self, tokenlist):
        """Generator to extract operators and operands in pairs."""
        it = iter(tokenlist)

        while 1:
            try:
                yield (it.next(), it.next())
            except StopIteration:
                break

    def operation(self, oper, result, val):
        return self.operations[oper](result, val)

    def get_children(self):
        return []

    def dependent_columns(self, dataset):
        return []


class EvalConstant(EvalTerm):
    """Class to evaluate a parsed constant or variable."""

    def eval(self, row, dataset):

# Path: bamboo/lib/datetools.py
# def now():
#     return datetime.now()
# 
# def parse_date_to_unix_time(date):
#     return timegm(date.utctimetuple())
# 
# def parse_str_to_unix_time(value):
#     return parse_date_to_unix_time(date_parse(value))
# 
# def safe_parse_date_to_unix_time(date):
#     if isinstance(date, datetime):
#         date = parse_date_to_unix_time(date)
# 
#     return date
# 
# Path: bamboo/lib/query_args.py
# class QueryArgs(object):
#     def __init__(self, query=None, select=None, distinct=None, limit=0,
#                  order_by=None, dataset=None):
#         """A holder for query arguments.
# 
#         :param query: An optional query.
#         :param select: An optional select to limit the fields in the dframe.
#         :param distinct: Return distinct entries for this field.
#         :param limit: Limit on the number of rows in the returned dframe.
#         :param order_by: Sort resulting rows according to a column value and
#             sign indicating ascending or descending.
# 
#         Example of `order_by`:
# 
#           - ``order_by='mycolumn'``
#           - ``order_by='-mycolumn'``
#         """
#         self.query = parse_dates_from_query(query, dataset)
#         self.select = select
#         self.distinct = distinct
#         self.limit = limit
#         self.order_by = parse_order_by(order_by)
# 
#     def encode(self, encoding, query):
#         """Encode query, order_by, and select given an encoding.
# 
#         The query will be combined with the existing query.
# 
#         :param encoding: A dict to encode the QueryArgs fields with.
#         :param query: An additional dict to combine with the existing query.
#         """
#         self.query = replace_keys(combine_dicts(self.query, query), encoding)
#         self.order_by = self.order_by and replace_keys(dict(self.order_by),
#                                                        encoding).items()
#         self.select = self.select and replace_keys(self.select, encoding)
# 
#     def __nonzero__(self):
#         return bool(self.query or self.select or self.distinct or self.limit
#                     or self.order_by)
# 
# Path: bamboo/lib/utils.py
# def parse_float(value, default=None):
#     return _parse_type(np.float64, value, default)


# Path: bamboo/core/operations.py
import operator
import numpy as np
from scipy.stats import percentileofscore
from bamboo.lib.datetools import now, parse_date_to_unix_time,\
    parse_str_to_unix_time, safe_parse_date_to_unix_time
from bamboo.lib.query_args import QueryArgs
from bamboo.lib.utils import parse_float

    """Base class for evaluation."""

    def __init__(self, tokens):
        self.tokens = tokens
        self.value = tokens[0]

    def operator_operands(self, tokenlist):
        """Generator to extract operators and operands in pairs."""
        it = iter(tokenlist)

        while 1:
            try:
                yield (it.next(), it.next())
            except StopIteration:
                break

    def operation(self, oper, result, val):
        return self.operations[oper](result, val)

    def get_children(self):
        return []

    def dependent_columns(self, dataset):
        return []


class EvalConstant(EvalTerm):
    """Class to evaluate a parsed constant or variable."""

    def eval(self, row, dataset):

        value = parse_float(self.value)