コード例 #1
0
ファイル: client.py プロジェクト: ibis-project/ibis
def _validate_compatible(from_schema, to_schema):
    if set(from_schema.names) != set(to_schema.names):
        raise com.IbisInputError('Schemas have different names')

    for name in from_schema:
        lt = from_schema[name]
        rt = to_schema[name]
        if not lt.castable(rt):
            raise com.IbisInputError(f'Cannot safely cast {lt!r} to {rt!r}')
コード例 #2
0
def analytic(arg, **kwargs):
    from ibis.expr.analysis import is_analytic

    if not is_analytic(arg):
        raise com.IbisInputError(
            'Expression does not contain a valid window operation')
    return arg
コード例 #3
0
ファイル: __init__.py プロジェクト: zbrookle/ibis
def time_range_to_range_window(translator, window):
    # Check that ORDER BY column is a single time column:
    order_by_vars = [x.op().args[0] for x in window._order_by]
    if len(order_by_vars) > 1:
        raise com.IbisInputError(
            "Expected 1 order-by variable, got {}".format(len(order_by_vars))
        )
コード例 #4
0
def _format_multilinestring_value(value: MultiLineStringType) -> str:
    """Convert a iterable with a multilinestring to text."""
    if not isinstance(value[0][0], (tuple, list)):
        raise ex.IbisInputError('Data structure expected: MultiLineStringType')
    return ', '.join(
        '({})'.format(_format_linestring_value(line)) for line in value
    )
コード例 #5
0
def _format_multipolygon_value(value: MultiPolygonType) -> str:
    """Convert a iterable with a multipolygon to text."""
    if not isinstance(value[0][0], (tuple, list)):
        raise ex.IbisInputError('Data structure expected: MultiPolygonType')
    return ', '.join(
        _format_polygon_value(polygon, nested=True) for polygon in value
    )
コード例 #6
0
ファイル: ddl.py プロジェクト: sarthakvk/ibis
    def __init__(
        self,
        table_name: str,
        cols_with_types: dict,
        nullables: Optional[list] = None,
        defaults: Optional[list] = None,
        encodings: Optional[list] = None,
    ):
        if len(cols_with_types) == 0:
            raise com.IbisInputError('No column requested to add.')
        else:
            self.col_count = len(cols_with_types)
        self.table_name = table_name
        self.cols_with_types = cols_with_types

        if not nullables:
            self.nullables = [True] * self.col_count
        else:
            self.nullables = nullables

        if not defaults:
            self.defaults = [None] * self.col_count
        else:
            self.defaults = defaults

        if not encodings:
            self.encodings = [None] * self.col_count
        else:
            self.encodings = encodings
コード例 #7
0
def _format_multipoint_value(value: MultiPointType) -> str:
    """Convert a iterable with a multipoint to text."""
    if not isinstance(value[0], (tuple, list)):
        raise ex.IbisInputError('Data structure expected: MultiPointType')
    return ', '.join(
        '({})'.format(_format_point_value(point)) for point in value
    )
コード例 #8
0
ファイル: client.py プロジェクト: LeeTZ/ibis
 def _get_jtable(self, name, database=None):
     try:
         jtable = self._catalog._jcatalog.getTable(
             _fully_qualified_name(name, database))
     except ps.sql.utils.AnalysisException as e:
         raise com.IbisInputError(str(e)) from e
     return jtable
コード例 #9
0
def _format_linestring_value(value: LineStringType, nested=False) -> str:
    """Convert a iterable with a linestring to text."""
    template = '({})' if nested else '{}'
    if not isinstance(value[0], (tuple, list)):
        msg = '{} structure expected: LineStringType'.format(
            'Data' if not nested else 'Inner data')
        raise ex.IbisInputError(msg)
    return template.format(', '.join(
        _format_point_value(point) for point in value))
コード例 #10
0
def _format_polygon_value(value: PolygonType, nested=False) -> str:
    """Convert a iterable with a polygon to text."""
    template = '({})' if nested else '{}'
    if not isinstance(value[0][0], (tuple, list)):
        msg = '{} data structure expected: PolygonType'.format(
            'Data' if not nested else 'Inner data')
        raise ex.IbisInputError(msg)

    return template.format(', '.join(
        _format_linestring_value(line, nested=True) for line in value))
コード例 #11
0
def window(win, *, from_base_table_of, this):
    from ibis.expr.window import Window

    if not isinstance(win, Window):
        raise com.IbisTypeError(
            "`win` argument should be of type `ibis.expr.window.Window`; "
            f"got type {type(win).__name__}")
    table = ir.find_base_table(getattr(this, from_base_table_of))
    if table is not None:
        win = win.bind(table)

    if win.max_lookback is not None:
        error_msg = ("'max lookback' windows must be ordered "
                     "by a timestamp column")
        if len(win._order_by) != 1:
            raise com.IbisInputError(error_msg)
        order_var = win._order_by[0].op().args[0]
        if not isinstance(order_var.type(), dt.Timestamp):
            raise com.IbisInputError(error_msg)
    return win
コード例 #12
0
ファイル: window.py プロジェクト: descarteslabs/ibis-orig
    def combine(self, window):
        if self.how != window.how:
            raise com.IbisInputError(
                ("Window types must match. "
                 "Expecting '{}' Window, got '{}'").format(
                     self.how.upper(), window.how.upper()))

        kwds = dict(
            preceding=_choose_non_empty_val(self.preceding, window.preceding),
            following=_choose_non_empty_val(self.following, window.following),
            max_lookback=self.max_lookback or window.max_lookback,
            group_by=self._group_by + window._group_by,
            order_by=self._order_by + window._order_by,
        )
        return Window(**kwds)
コード例 #13
0
def _time_range_to_range_window(translator, window):
    # Check that ORDER BY column is a single time column:
    order_by_vars = [x.op().args[0] for x in window._order_by]
    if len(order_by_vars) > 1:
        raise com.IbisInputError("Expected 1 order-by variable, got {}".format(
            len(order_by_vars)))

    order_var = window._order_by[0].op().args[0]
    timestamp_order_var = order_var.cast('int64')
    window = window._replace(order_by=timestamp_order_var, how='range')

    # Need to change preceding interval expression to scalars
    preceding = window.preceding
    if isinstance(preceding, ir.IntervalScalar):
        new_preceding = _replace_interval_with_scalar(preceding)
        window = window._replace(preceding=new_preceding)

    return window
コード例 #14
0
ファイル: client.py プロジェクト: reshma-katkar/ibis
    def _check_execution_type(self, ipc: Optional[bool],
                              gpu_device: Optional[int]):
        """
        Check if the execution type (ipc and gpu_device) is valid.

        Parameters
        ----------
        ipc : bool, optional
        gpu_device : int, optional

        Raises
        ------
        com.IbisInputError
            if "gpu_device" is not None and "ipc" is False
        """
        if gpu_device is not None and ipc is False:
            raise com.IbisInputError(
                'If GPU device is provided, IPC parameter should '
                'be True or None (default).')
コード例 #15
0
ファイル: client.py プロジェクト: reshma-katkar/ibis
    def _execute(
        self,
        query: str,
        results: bool = True,
        ipc: Optional[bool] = None,
        gpu_device: Optional[int] = None,
        **kwargs,
    ):
        """
        Compile and execute Ibis expression.

        Return result in-memory in the appropriate object type.

        Parameters
        ----------
        query : string
          DML or DDL statement
        results : boolean, default False
          Pass True if the query as a result set
        ipc : bool, optional, default None
          Enable Inter Process Communication (IPC) execution type.
          `ipc` default value (None) when `gpu_device` is None is interpreted
           as False, otherwise it is interpreted as True.
        gpu_device : int, optional, default None
          GPU device ID.

        Returns
        -------
        output : execution type dependent
          If IPC is set as True and no GPU device is set:
            ``pandas.DataFrame``
          If IPC is set as True and GPU device is set: ``cudf.DataFrame``
          If IPC is set as False and no GPU device is set:
            pandas.DataFrame or
            geopandas.GeoDataFrame (if it uses geospatial data)

        Raises
        ------
        Exception
            if execution method fails.
        """
        # time context is not implemented for omniscidb yet
        kwargs.pop('timecontext', None)
        # raise an Exception if kwargs is not empty:
        if kwargs:
            raise com.IbisInputError(
                '"OmniSciDB.execute" method just support the follow parameter:'
                ' "query", "results", "ipc" and "gpu_device". The follow extra'
                ' parameters was given: "{}".'.format(', '.join(
                    kwargs.keys())))

        if isinstance(query, (DDL, DML)):
            query = query.compile()

        if ipc is None and gpu_device is None:
            ipc = self.ipc
            gpu_device = self.gpu_device

        self._check_execution_type(ipc, gpu_device)

        cursor = (OmniSciDBGeoCursor
                  if FULL_GEO_SUPPORTED else OmniSciDBDefaultCursor)

        params = {}

        if gpu_device is None and not ipc:
            execute = self.con.cursor().execute
        elif gpu_device is None and ipc:
            execute = self.con.select_ipc
        else:
            params['device_id'] = gpu_device
            execute = self.con.select_ipc_gpu
            cursor = OmniSciDBGPUCursor

        try:
            result = cursor(execute(query, **params))
        except Exception as e:
            raise Exception('{}: {}'.format(e, query))

        if results:
            return result
コード例 #16
0
    def _validate_frame(self):
        preceding_tuple = has_preceding = False
        following_tuple = has_following = False
        if self.preceding is not None:
            preceding_tuple = isinstance(self.preceding, tuple)
            has_preceding = True

        if self.following is not None:
            following_tuple = isinstance(self.following, tuple)
            has_following = True

        if (preceding_tuple and has_following) or (
            following_tuple and has_preceding
        ):
            raise com.IbisInputError(
                'Can only specify one window side when you want an '
                'off-center window'
            )
        elif preceding_tuple:
            start, end = self.preceding
            if end is None:
                raise com.IbisInputError("preceding end point cannot be None")
            if end < 0:
                raise com.IbisInputError(
                    "preceding end point must be non-negative"
                )
            if start is not None:
                if start < 0:
                    raise com.IbisInputError(
                        "preceding start point must be non-negative"
                    )
                if start <= end:
                    raise com.IbisInputError(
                        "preceding start must be greater than preceding end"
                    )
        elif following_tuple:
            start, end = self.following
            if start is None:
                raise com.IbisInputError(
                    "following start point cannot be None"
                )
            if start < 0:
                raise com.IbisInputError(
                    "following start point must be non-negative"
                )
            if end is not None:
                if end < 0:
                    raise com.IbisInputError(
                        "following end point must be non-negative"
                    )
                if start >= end:
                    raise com.IbisInputError(
                        "following start must be less than following end"
                    )
        else:
            if not isinstance(self.preceding, ir.Expr):
                if has_preceding and self.preceding < 0:
                    raise com.IbisInputError(
                        "'preceding' must be positive, got {}".format(
                            self.preceding
                        )
                    )

            if not isinstance(self.following, ir.Expr):
                if has_following and self.following < 0:
                    raise com.IbisInputError(
                        "'following' must be positive, got {}".format(
                            self.following
                        )
                    )
        if self.how not in {'rows', 'range'}:
            raise com.IbisInputError(
                "'how' must be 'rows' or 'range', got {}".format(self.how)
            )

        if self.max_lookback is not None:
            if not isinstance(
                    self.preceding, (ir.IntervalValue, pd.Timedelta)):
                raise com.IbisInputError(
                    "'max_lookback' must be specified as an interval "
                    "or pandas.Timedelta object"
                )
コード例 #17
0
ファイル: ddl.py プロジェクト: sarthakvk/ibis
 def __init__(self, table_name: str, column_names: list):
     if len(column_names) == 0:
         raise com.IbisInputError('No column requested to drop.')
     self.table_name = table_name
     self.column_names = column_names
コード例 #18
0
ファイル: udf.py プロジェクト: randxie/ibis
 def _check_library(self):
     suffix = self.lib_path[-3:]
     if suffix == '.ll':
         raise com.IbisInputError('LLVM IR UDAs are not yet supported')
     elif suffix != '.so':
         raise ValueError('Invalid file type. Must be .so')