Skip to content

Commit

Permalink
BUG lara index bug; closes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgoodman committed Feb 11, 2014
1 parent 789d46f commit 5775a40
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ After you have installed ``la``, run the suite of unit tests::
>>> import la
>>> la.test()
<snip>
Ran 3005 tests in 12.225s
Ran 3006 tests in 12.225s
OK
<nose.result.TextTestResult run=3005 errors=0 failures=0>
<nose.result.TextTestResult run=3006 errors=0 failures=0>

The ``la`` package contains C extensions that speed up common alignment
operations such as adding two unaligned larrys. If the C extensions don't
Expand Down
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ la 0.7

**Bug fixes**

- #40 lara indexing bug when index is a list
- #59 Proper int promotion in larry.cumsum() and larry.cumprod()
- #62 la.cov() overwrites NaNs in input array
- #65 lar.any() and lar.all() return wrong dtype with size=0 input
Expand Down
13 changes: 12 additions & 1 deletion la/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,18 @@ def __init__(self, filename, key):
def __getitem__(self, index):
f = h5py.File(self.filename, 'r')
self.x = f[self.key]['x']
lar = self._larry_getitem(index)
if isinstance(index, list):
# at this point self.x is a h5py Dataset object, which doesn't
# have a take method, so do the indexing here instead of asking
# larry to do it.
label = list(self.label)
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
lar = larry(self.x[index], label, validate=False)
else:
lar = self._larry_getitem(index)
f.close()
self.x = None
return lar
Expand Down
9 changes: 9 additions & 0 deletions la/tests/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ def test_io_load_2(self):
la.io.delete(f, 'd')
f.close()

def test_io_lara_1(self):
"lara indexing bug #40"
io = IO(self.filename)
io['a'] = la.lrange(3)
b = io['a']
# b[[0, 2]] raised:
# AttributeError: 'Dataset' object has no attribute 'take'
b[[0,2]]

# nose tests ----------------------------------------------------------------

def datetime_test():
Expand Down

0 comments on commit 5775a40

Please sign in to comment.