From dceb7b6c7d80654cebb8b0aaefb1e8fd95e9b704 Mon Sep 17 00:00:00 2001 From: "Jonathan J. Helmus" Date: Fri, 20 Jul 2012 15:39:40 -0400 Subject: [PATCH] variable name changes and small fixes --- skimage/io/collection.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/skimage/io/collection.py b/skimage/io/collection.py index e83a5b18..a78dbd14 100644 --- a/skimage/io/collection.py +++ b/skimage/io/collection.py @@ -267,8 +267,11 @@ class ImageCollection(object): Imagecollection of the selected images or an ndarray if a single image is specified. """ + if hasattr(n, '__index__'): + n = n.__index__() + if type(n) not in [int, slice]: - raise TypeError('slicing must be an int or slice object') + raise TypeError('slicing must be with an int or slice object') if type(n) is int: n = self._check_imgnum(n) @@ -283,7 +286,6 @@ class ImageCollection(object): else: # slice object was provided fidx = range(len(self.files))[n] - fidx.sort() if len(fidx) == 1: # only one item requested return self.__getitem__(fidx[0]) else: @@ -291,18 +293,19 @@ class ImageCollection(object): # in the original ImageCollection will be copied by reference # to the new object. Image data loaded after this creation # are not linked. - newIC = copy(self) - newIC._files = [self.files[i] for i in fidx] + fidx.sort() + new_ic = copy(self) + new_ic._files = [self.files[i] for i in fidx] if self.conserve_memory: if self._cached in fidx: - newIC._cached = fidx[self._cached] - newIC.data = np.copy(self.data) + new_ic._cached = fidx[self._cached] + new_ic.data = np.copy(self.data) else: - newIC.data = np.empty(1, dtype=object) + new_ic.data = np.empty(1, dtype=object) else: - newIC.data = self.data[fidx] + new_ic.data = self.data[fidx] - return newIC + return new_ic def _check_imgnum(self, n): """Check that the given image number is valid."""