Permalink
Browse files

ENH Faster larry indexing.

  • Loading branch information...
1 parent 56b9b47 commit 46712b9f8273d6abc6dd4ae7bf16649b104d28ed @kwgoodman committed Mar 26, 2012
Showing with 15 additions and 8 deletions.
  1. +1 −1 RELEASE.rst
  2. +13 −6 la/deflarry.py
  3. +1 −1 la/tests/deflarry_test.py
View
@@ -13,7 +13,7 @@ la 0.7
**Faster**
-- Indexing into larrys with scalars, slices, and 1d bool numpy arrays
+- Indexing into larrys with scalars, slices, and 1d numpy arrays
- Binary functions (+, -, / , &, ...) for unaligned larrys
- la.align(), la.add(), la.subtract(), etc for unaligned larrys
- la.union(), la.intersection()
View
@@ -1699,9 +1699,14 @@ def __getitem__(self, index):
validate = False
elif typidx is list:
label = list(self.label)
- label[0] = [label[0][int(i)] for i in index]
- x = self.x.take(index, axis=0)
+ lab = [label[0][int(i)] for i in index]
+ if len(set(lab)) != len(lab):
+ raise IndexError("Duplicate labels along axis 0.")
+ label[0] = lab
+ x = self.x.take(index, axis=0)
+ validate = False
elif typidx is np.ndarray:
+ validate = False
if index.ndim != 1:
msg = 'You can use a Numpy array for indexing, '
msg += 'but it must be 1d.'
@@ -1712,15 +1717,17 @@ def __getitem__(self, index):
enumerate(index) if z]
except IndexError:
raise IndexError, 'index out of range'
- validate = False
+ x = self.x[index]
else:
try:
lab = [self.label[0][z] for z in index]
except IndexError:
- raise IndexError, 'index out of range'
+ raise IndexError, 'index out of range'
+ if len(set(lab)) != len(lab):
+ raise IndexError("Duplicate labels along axis 0.")
+ x = self.x.take(index, axis=0)
label = self.copylabel()
- label[0] = lab
- x = self.x[index]
+ label[0] = lab
else:
msg = 'Only slice, integer, and seq (list, tuple, 1d array)'
msg = msg + ' indexing supported'
@@ -2226,7 +2226,7 @@ def test_getitem_14(self):
def test_getitem_15(self):
"larry.__getitem___15"
- self.failUnlessRaises(ValueError, self.l.__getitem__, [0,1,0])
+ self.failUnlessRaises(IndexError, self.l.__getitem__, [0,1,0])
def test_getitem_16(self):
"larry.__getitem___16"

0 comments on commit 46712b9

Please sign in to comment.