How to use the larray.AxisCollection._key_to_igroups 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
nonboolkey.extend(axis_key.nonzero())
        else:
            nonboolkey.append(axis_key)
    key = tuple(nonboolkey)

    # drop slice(None) and Ellipsis since they are meaningless because of guess_axis.
    # XXX: we might want to raise an exception when we find Ellipses or (most) slice(None) because except for
    #      a single slice(None) a[:], I don't think there is any point.
    key = [axis_key for axis_key in key
           if not _isnoneslice(axis_key) and axis_key is not Ellipsis]

    # translate all keys to IGroup
    return tuple(self._translate_axis_key(axis_key) for axis_key in key)


la.AxisCollection._key_to_igroups = _key_to_igroups


# Monkey patch to fix support for "long" required for Python 2, especially on Linux.
# Changed lines are marked with "MONKEY PATCH CHANGED LINE"
def _key_to_raw_and_axes(self, key, collapse_slices=False, translate_key=True):
    r"""
    Transforms any key (from Array.__getitem__) to a raw numpy key, the resulting axes, and potentially a tuple
    of indices to transpose axes back to where they were.

    Parameters
    ----------
    key : scalar, list/array of scalars, Group or tuple or dict of them
        any key supported by Array.__getitem__
    collapse_slices : bool, optional
        Whether or not to convert ranges to slices. Defaults to False.