How to use the larray.core.expr.ExprNode function in larray

To help you get started, we’ve selected a few larray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liam2 / liam2 / liam2 / larray_monkey.py View on Github external
tuple of IGroup, each IGroup having a real axis from this array.
        The order of the IGroups is *not* guaranteed to be the same as the order of axes.

    See Also
    --------
    Axis.index
    """
    if isinstance(key, dict):
        # key axes could be strings or axis references and we want real axes
        key = tuple(self[axis][axis_key] for axis, axis_key in key.items())
    elif not isinstance(key, tuple):
        # convert scalar keys to 1D keys
        key = (key,)

    # handle ExprNode
    key = tuple(axis_key.evaluate(self) if isinstance(axis_key, ExprNode) else axis_key
                for axis_key in key)

    nonboolkey = []
    for axis_key in key:
        if isinstance(axis_key, np.ndarray) and np.issubdtype(axis_key.dtype, np.bool_):
            if axis_key.shape != self.shape:
                raise ValueError("boolean key with a different shape ({}) than array ({})"
                                 .format(axis_key.shape, self.shape))
            axis_key = la.Array(axis_key, self)

        if isinstance(axis_key, la.Array) and np.issubdtype(axis_key.dtype, np.bool_):
            bool_axes_names = [axis.name for axis in self if np.issubdtype(axis.dtype, np.bool_)]
            if bool_axes_names:
                # a "filter" key has always somme axes in common with the array (it should be a subset of the array
                # axes), so if there is no common axis, it is not a filter key.