<commit_before>from numpy import asarray

class ImageList:

    def __init__(self, images=None):
        """
        
        A lightweight implementation of a list of images.

        Parameters
        ----------
        images: a sliceable object whose items are meant to be images,
                this is checked by asserting that each has a `grid` attribute

        >>> from numpy import asarray
        >>> from neuroimaging.testing funcfile
        >>> from neuroimaging.core.image.image_list import ImageList
        >>> from neuroimaging.modalities.fmri.api import load_image

        >>> funcim = load_image(funcfile)
        >>> ilist = ImageList(funcim)
        >>> print ilist[2:5]
        
        >>> print ilist[2]
        
        >>> print asarray(ilist).shape
        >>> print asarray(ilist[4]).shape

        """
        if images is not None:
            for im in images:
                if not hasattr(im, "grid"):
                    raise ValueError, "expecting each element of images to have a 'grid' attribute"
            self.list = images
        else:
            self.list = []

    def __setitem__(self, index, value):
        """
        self.list[index] = value
        """
        
        self.list[index] = value

    def __getitem__(self, index):
        """
        self.list[index]
        """
        return self.list[index]

    def __getslice__(self, i, j):
        """
        Return another ImageList instance consisting with
        images self.list[i:j]
        """
        
        return ImageList(images=self.list[i:j])

    def __array__(self):
        """Return data in ndarray.  Called through numpy.array.
        
        Examples
        --------
        >>> from numpy import asarray
        >>> from neuroimaging.testing funcfile
        >>> from neuroimaging.core.image.image_list import ImageList
        >>> from neuroimaging.modalities.fmri.api import load_image

        >>> print asarray(ilist).shape


        """

        return asarray([asarray(im) for im in self.list])

    def __iter__(self):
        self._iter = iter(self.list)
        return self

    def next(self):
        return self._iter.next()

<commit_msg>fixing ImageList.__getitem__ for slcies<commit_after>from numpy import asarray

class ImageList:

    def __init__(self, images=None):
        """
        
        A lightweight implementation of a list of images.

        Parameters
        ----------
        images: a sliceable object whose items are meant to be images,
                this is checked by asserting that each has a `grid` attribute

        >>> from numpy import asarray
        >>> from neuroimaging.testing funcfile
        >>> from neuroimaging.core.image.image_list import ImageList
        >>> from neuroimaging.modalities.fmri.api import load_image

        >>> funcim = load_image(funcfile)
        >>> ilist = ImageList(funcim)
        >>> print ilist[2:5]
        
        >>> print ilist[2]
        
        >>> print asarray(ilist).shape
        >>> print asarray(ilist[4]).shape

        """
        if images is not None:
            for im in images:
                if not hasattr(im, "grid"):
                    raise ValueError, "expecting each element of images to have a 'grid' attribute"
            self.list = images
        else:
            self.list = []

    def __setitem__(self, index, value):
        """
        self.list[index] = value
        """
        
        self.list[index] = value

    def __getitem__(self, index):
        """
        self.list[index]
        """
        if type(index) is type(1):
            return self.list[index]
        else:
            return ImageList(images=self.list[index])

    def __getslice__(self, i, j):
        """
        Return another ImageList instance consisting with
        images self.list[i:j]
        """
        
        return ImageList(images=self.list[i:j])

    def __array__(self):
        """Return data in ndarray.  Called through numpy.array.
        
        Examples
        --------
        >>> from numpy import asarray
        >>> from neuroimaging.testing funcfile
        >>> from neuroimaging.core.image.image_list import ImageList
        >>> from neuroimaging.modalities.fmri.api import load_image

        >>> print asarray(ilist).shape


        """

        return asarray([asarray(im) for im in self.list])

    def __iter__(self):
        self._iter = iter(self.list)
        return self

    def next(self):
        return self._iter.next()


{'fraction_non_alphanumeric': 0.10476190476190476, 'fraction_numerical': 0.0019933554817275745, 'mean_word_length': 1.768853464132434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2476399', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1183, 'n_words': 344}