# Path: purplequery/bq_types.py
# class BQScalarType(BQType, enum.Enum):
#     """Representation of basic (scalar) BigQuery types as an enum."""
# 
#     __metaclass__ = AbstractEnumMeta
# 
#     BOOLEAN = 'BOOLEAN'
#     DATE = 'DATE'
#     DATETIME = 'DATETIME'
#     INTEGER = 'INTEGER'
#     FLOAT = 'FLOAT'
#     STRING = 'STRING'
#     TIMESTAMP = 'TIMESTAMP'
# 
#     def to_dtype(self):
#         # type: () -> np.dtype
#         """Converts this BigQuery type to a NumPy dtype.
# 
#         Returns:
#            A NumPy dtype corresponding to this BigQuery type (e.g. np.dtype('int64') for INTEGER)
#         """
#         return np.dtype(_BQ_SCALAR_TYPE_TO_NUMPY_TYPE[self])
# 
#     @classmethod
#     def from_string(cls, typename):
#         # type: (str) -> BQScalarType
#         """Reads this type from a string representation.
# 
#         A Factory method constructing an instance of BQScalarType corresponding to typename.
#         The reason for not just using the inherited Enum constructor is to allow Standard BigQuery
#         typenames to be aliases for Legacy typenames.
# 
#         Args:
#             typename: A BigQuery type name, either Legacy (INTEGER, FLOAT, ...) or Standard
#             (INT64, FLOAT64, ...).
# 
#         Returns:
#             The corresponding BQScalarType enum.
#         """
#         if isinstance(typename, str):
#             typename = typename.upper()
#         if typename in _LEGACY_BQ_SCALAR_TYPE_FROM_BQ_SCALAR_TYPE:
#             return _LEGACY_BQ_SCALAR_TYPE_FROM_BQ_SCALAR_TYPE[typename]
#         return cls(typename)
# 
#     def to_schema_field(self, name):
#         # type: (str) -> SchemaField
#         """Converts this type to a BigQuery SchemaField.
# 
#         Args:
#             name: The name of the column.  This class represents a type; SchemaField represents
#             a column, so it includes the type and also the name of the column.
# 
#         Returns:
#             A SchemaField object corresponding to a column containing this class' type.
#         """
#         return SchemaField(name=name, field_type=self.value)
# 
#     def __repr__(self):
#         return 'BQScalarType.{}'.format(self.value)
# 
#     def convert(self, element):
#         # type: (PandasType) -> ScalarPythonType
#         """Converts a pandas Series element to a Python type corresponding to this BigQuery type.
# 
#         Args:
#             element: One cell of a Pandas DataFrame or Series.  Will have numpy types like np.int64
#             rather than a Python type like int.
# 
#         Returns:
#             The element's value, cast to a corresponding Python type.
#         """
#         if pd.isnull(element):
#             return None
#         return _BQ_SCALAR_TYPE_TO_PYTHON_TYPE[self](element)
# 
# class BQType(object):
#     """Representation of a BigQuery column data type."""
# 
#     __metaclass__ = ABCMeta
# 
#     def to_dtype(self):
#         # type: () -> np.dtype
#         """Converts this BigQuery type to a NumPy dtype.
# 
#         Returns:
#            'object' dtype, meaning NumPy will not try to interpret the type and will leave it
#            as a Python object.
# 
#            Subclasses may override this function to return a more specific NumPy dtype.
#         """
#         return np.dtype('object')
# 
#     @classmethod
#     def from_schema_field(cls, field):
#         # type: (SchemaField) -> BQType
#         """Converts from a BigQuery SchemaField object to a BQType subclass.
# 
#         This is a factory function, that constructs an object of the appropriate child class.
# 
#         Args:
#             field: A BigQuery SchemaField object, the google cloud bigquery Python API
#             representation of a column type.
# 
#         Returns:
#             An instance of a BQType subclass that corresponds to the input type.
#         """
#         if field.mode in ('ARRAY', 'REPEATED'):
#             return BQArray(BQScalarType.from_string(field.field_type))
#         return BQScalarType.from_string(field.field_type)
# 
#     @abstractmethod
#     def to_schema_field(self, name):
#         # type: (str) -> SchemaField
#         """Converts this type to a BigQuery SchemaField.
# 
#         Args:
#             name: The name of the column.  This class represents a type; SchemaField represents
#             a column, so it includes the type and also the name of the column.
#         Returns:
#             A SchemaField object corresponding to a column containing this class' type.
# 
#         This abstract method always raises NotImplementedError; child classes will override
#         with an appropriate implementation.
#         """
# 
#     @abstractmethod
#     def convert(self, element):
#         # type: (PandasType) -> PythonType
#         """Converts a pandas Series element to a Python type corresponding to this BigQuery type.
# 
#         Args:
#             element: One cell of a Pandas DataFrame or Series.  Will have numpy types like np.int64
#             rather than a Python type like int.
# 
#         Returns:
#             The element's value, cast to a corresponding Python type.
#         """


import operator
import numpy as np
from typing import Callable, NamedTuple, Optional
from .bq_types import BQScalarType, BQType
# Copyright 2019 Verily Life Sciences LLC
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

"""Information about binary operators.

Includes the operator's: string representation, precedence, function, and
result type (if known in advance).
"""




"""Tuple for storing operator info.

    Attributes:
        operator: The character(s) that represent this operator.
        precedence: Lower number means earlier in order of operations.
        function: The actual function describing the action the operator performs.
        result_type: The type of the operation's result, or None if type depends on
            additional information.
"""
_OperatorInfo = NamedTuple('_OperatorInfo', [
    ('operator', str),
    ('precedence', int),
    ('function', Callable),

# Path: purplequery/bq_types.py
# class BQScalarType(BQType, enum.Enum):
#     """Representation of basic (scalar) BigQuery types as an enum."""
# 
#     __metaclass__ = AbstractEnumMeta
# 
#     BOOLEAN = 'BOOLEAN'
#     DATE = 'DATE'
#     DATETIME = 'DATETIME'
#     INTEGER = 'INTEGER'
#     FLOAT = 'FLOAT'
#     STRING = 'STRING'
#     TIMESTAMP = 'TIMESTAMP'
# 
#     def to_dtype(self):
#         # type: () -> np.dtype
#         """Converts this BigQuery type to a NumPy dtype.
# 
#         Returns:
#            A NumPy dtype corresponding to this BigQuery type (e.g. np.dtype('int64') for INTEGER)
#         """
#         return np.dtype(_BQ_SCALAR_TYPE_TO_NUMPY_TYPE[self])
# 
#     @classmethod
#     def from_string(cls, typename):
#         # type: (str) -> BQScalarType
#         """Reads this type from a string representation.
# 
#         A Factory method constructing an instance of BQScalarType corresponding to typename.
#         The reason for not just using the inherited Enum constructor is to allow Standard BigQuery
#         typenames to be aliases for Legacy typenames.
# 
#         Args:
#             typename: A BigQuery type name, either Legacy (INTEGER, FLOAT, ...) or Standard
#             (INT64, FLOAT64, ...).
# 
#         Returns:
#             The corresponding BQScalarType enum.
#         """
#         if isinstance(typename, str):
#             typename = typename.upper()
#         if typename in _LEGACY_BQ_SCALAR_TYPE_FROM_BQ_SCALAR_TYPE:
#             return _LEGACY_BQ_SCALAR_TYPE_FROM_BQ_SCALAR_TYPE[typename]
#         return cls(typename)
# 
#     def to_schema_field(self, name):
#         # type: (str) -> SchemaField
#         """Converts this type to a BigQuery SchemaField.
# 
#         Args:
#             name: The name of the column.  This class represents a type; SchemaField represents
#             a column, so it includes the type and also the name of the column.
# 
#         Returns:
#             A SchemaField object corresponding to a column containing this class' type.
#         """
#         return SchemaField(name=name, field_type=self.value)
# 
#     def __repr__(self):
#         return 'BQScalarType.{}'.format(self.value)
# 
#     def convert(self, element):
#         # type: (PandasType) -> ScalarPythonType
#         """Converts a pandas Series element to a Python type corresponding to this BigQuery type.
# 
#         Args:
#             element: One cell of a Pandas DataFrame or Series.  Will have numpy types like np.int64
#             rather than a Python type like int.
# 
#         Returns:
#             The element's value, cast to a corresponding Python type.
#         """
#         if pd.isnull(element):
#             return None
#         return _BQ_SCALAR_TYPE_TO_PYTHON_TYPE[self](element)
# 
# class BQType(object):
#     """Representation of a BigQuery column data type."""
# 
#     __metaclass__ = ABCMeta
# 
#     def to_dtype(self):
#         # type: () -> np.dtype
#         """Converts this BigQuery type to a NumPy dtype.
# 
#         Returns:
#            'object' dtype, meaning NumPy will not try to interpret the type and will leave it
#            as a Python object.
# 
#            Subclasses may override this function to return a more specific NumPy dtype.
#         """
#         return np.dtype('object')
# 
#     @classmethod
#     def from_schema_field(cls, field):
#         # type: (SchemaField) -> BQType
#         """Converts from a BigQuery SchemaField object to a BQType subclass.
# 
#         This is a factory function, that constructs an object of the appropriate child class.
# 
#         Args:
#             field: A BigQuery SchemaField object, the google cloud bigquery Python API
#             representation of a column type.
# 
#         Returns:
#             An instance of a BQType subclass that corresponds to the input type.
#         """
#         if field.mode in ('ARRAY', 'REPEATED'):
#             return BQArray(BQScalarType.from_string(field.field_type))
#         return BQScalarType.from_string(field.field_type)
# 
#     @abstractmethod
#     def to_schema_field(self, name):
#         # type: (str) -> SchemaField
#         """Converts this type to a BigQuery SchemaField.
# 
#         Args:
#             name: The name of the column.  This class represents a type; SchemaField represents
#             a column, so it includes the type and also the name of the column.
#         Returns:
#             A SchemaField object corresponding to a column containing this class' type.
# 
#         This abstract method always raises NotImplementedError; child classes will override
#         with an appropriate implementation.
#         """
# 
#     @abstractmethod
#     def convert(self, element):
#         # type: (PandasType) -> PythonType
#         """Converts a pandas Series element to a Python type corresponding to this BigQuery type.
# 
#         Args:
#             element: One cell of a Pandas DataFrame or Series.  Will have numpy types like np.int64
#             rather than a Python type like int.
# 
#         Returns:
#             The element's value, cast to a corresponding Python type.
#         """


# Path: purplequery/bq_binary_operators.py
import operator
import numpy as np
from typing import Callable, NamedTuple, Optional
from .bq_types import BQScalarType, BQType

# Copyright 2019 Verily Life Sciences LLC
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

"""Information about binary operators.

Includes the operator's: string representation, precedence, function, and
result type (if known in advance).
"""




"""Tuple for storing operator info.

    Attributes:
        operator: The character(s) that represent this operator.
        precedence: Lower number means earlier in order of operations.
        function: The actual function describing the action the operator performs.
        result_type: The type of the operation's result, or None if type depends on
            additional information.
"""
_OperatorInfo = NamedTuple('_OperatorInfo', [
    ('operator', str),
    ('precedence', int),
    ('function', Callable),

    ('result_type', Optional[BQType])])