Skip to content

Commit

Permalink
BUG la.align() crash with empty larrys, closes #67
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgoodman committed Feb 11, 2014
1 parent 5775a40 commit ae67e20
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -120,9 +120,9 @@ After you have installed ``la``, run the suite of unit tests::
>>> import la >>> import la
>>> la.test() >>> la.test()
<snip> <snip>
Ran 3006 tests in 12.225s Ran 3008 tests in 12.225s
OK OK
<nose.result.TextTestResult run=3006 errors=0 failures=0> <nose.result.TextTestResult run=3008 errors=0 failures=0>


The ``la`` package contains C extensions that speed up common alignment The ``la`` package contains C extensions that speed up common alignment
operations such as adding two unaligned larrys. If the C extensions don't operations such as adding two unaligned larrys. If the C extensions don't
Expand Down
1 change: 1 addition & 0 deletions RELEASE.rst
Expand Up @@ -45,6 +45,7 @@ la 0.7
- #59 Proper int promotion in larry.cumsum() and larry.cumprod() - #59 Proper int promotion in larry.cumsum() and larry.cumprod()
- #62 la.cov() overwrites NaNs in input array - #62 la.cov() overwrites NaNs in input array
- #65 lar.any() and lar.all() return wrong dtype with size=0 input - #65 lar.any() and lar.all() return wrong dtype with size=0 input
- #67 la.align() crash with empty larrys
- #68 h5py prevents archiving of empty larrys - #68 h5py prevents archiving of empty larrys
- #69, #70 Unit test failures on Windows - #69, #70 Unit test failures on Windows
- #71 la.stack() Python 3.3 unit test failure - #71 la.stack() Python 3.3 unit test failure
Expand Down
28 changes: 24 additions & 4 deletions la/flarry.py
Expand Up @@ -300,8 +300,18 @@ def align_raw(lar1, lar2, join='inner', cast=True):
list3.sort() list3.sort()
idx1, idx1_miss = listmap_fill(list1, list3, fill=0) idx1, idx1_miss = listmap_fill(list1, list3, fill=0)
idx2, idx2_miss = listmap_fill(list2, list3, fill=0) idx2, idx2_miss = listmap_fill(list2, list3, fill=0)
x1 = x1.take(idx1, ax) if x1.size == 0:
x2 = x2.take(idx2, ax) shape = list(x1.shape)
shape[ax] = len(idx1)
x1 = np.ones(shape, dtype=x1.dtype)
else:
x1 = x1.take(idx1, ax)
if x2.size == 0:
shape = list(x2.shape)
shape[ax] = len(idx2)
x2 = np.ones(shape, dtype=x2.dtype)
else:
x2 = x2.take(idx2, ax)
if len(idx1_miss) > 0: if len(idx1_miss) > 0:
if miss1 == undefined: if miss1 == undefined:
miss1 = missing_marker(lar1) miss1 = missing_marker(lar1)
Expand Down Expand Up @@ -332,7 +342,12 @@ def align_raw(lar1, lar2, join='inner', cast=True):
list3 = list(list1) list3 = list(list1)
if list1 != list2: if list1 != list2:
idx2, idx2_miss = listmap_fill(list2, list3, fill=0) idx2, idx2_miss = listmap_fill(list2, list3, fill=0)
x2 = x2.take(idx2, ax) if x2.size == 0:
shape = list(x2.shape)
shape[ax] = len(idx2)
x2 = np.ones(shape, dtype=x2.dtype)
else:
x2 = x2.take(idx2, ax)
if len(idx2_miss) > 0: if len(idx2_miss) > 0:
if miss2 == undefined: if miss2 == undefined:
miss2 = missing_marker(lar2) miss2 = missing_marker(lar2)
Expand All @@ -354,7 +369,12 @@ def align_raw(lar1, lar2, join='inner', cast=True):
list3 = list(list2) list3 = list(list2)
if list1 != list2: if list1 != list2:
idx1, idx1_miss = listmap_fill(list1, list3, fill=0) idx1, idx1_miss = listmap_fill(list1, list3, fill=0)
x1 = x1.take(idx1, ax) if x1.size == 0:
shape = list(x1.shape)
shape[ax] = len(idx1)
x1 = np.ones(shape, dtype=x1.dtype)
else:
x1 = x1.take(idx1, ax)
if len(idx1_miss) > 0: if len(idx1_miss) > 0:
if miss1 == undefined: if miss1 == undefined:
miss1 = missing_marker(lar1) miss1 = missing_marker(lar1)
Expand Down
20 changes: 20 additions & 0 deletions la/tests/flarry_test.py
Expand Up @@ -401,6 +401,16 @@ def test_1d21(self):
ale(a1, d1, msg % 'left', original=y1) ale(a1, d1, msg % 'left', original=y1)
ale(a2, d2, msg % 'right', original=y2) ale(a2, d2, msg % 'right', original=y2)


def test_1d22(self):
"la.align() crash with empty larrys (gh #67)"
a = larry([])
b = larry([1, 2, 3])
for j in ('inner', 'outer', 'left', 'right', 'skip'):
align(a, a, join=j)
align(b, b, join=j)
align(a, b, join=j)
align(b, a, join=j)

class Test_align_2d(unittest.TestCase): class Test_align_2d(unittest.TestCase):
"Test 2d alignment of larrys" "Test 2d alignment of larrys"


Expand Down Expand Up @@ -516,6 +526,16 @@ def test_2d11(self):
ale(a1, d1, msg % 'left', original=y1) ale(a1, d1, msg % 'left', original=y1)
ale(a2, d2, msg % 'right', original=y2) ale(a2, d2, msg % 'right', original=y2)


def test_2d22(self):
"la.align() crash with empty larrys (gh #67)"
a = larry([[]])
b = larry([[1, 2, 3], [4, 5, 6]])
for j in ('inner', 'outer', 'left', 'right', 'skip'):
align(a, a, join=j)
align(b, b, join=j)
align(a, b, join=j)
align(b, a, join=j)

class Test_align_axis(unittest.TestCase): class Test_align_axis(unittest.TestCase):
"Test align_axis on larrys" "Test align_axis on larrys"


Expand Down

0 comments on commit ae67e20

Please sign in to comment.