Permalink
Browse files

BUG la.align() crash with empty larrys, closes #67

  • Loading branch information...
1 parent 5775a40 commit ae67e200d5545a4dcaf705c59cc2cffd12362920 @kwgoodman committed Feb 11, 2014
Showing with 47 additions and 6 deletions.
  1. +2 −2 README.rst
  2. +1 −0 RELEASE.rst
  3. +24 −4 la/flarry.py
  4. +20 −0 la/tests/flarry_test.py
View
@@ -120,9 +120,9 @@ After you have installed ``la``, run the suite of unit tests::
>>> import la
>>> la.test()
<snip>
- Ran 3006 tests in 12.225s
+ Ran 3008 tests in 12.225s
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
operations such as adding two unaligned larrys. If the C extensions don't
View
@@ -45,6 +45,7 @@ la 0.7
- #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
+- #67 la.align() crash with empty larrys
- #68 h5py prevents archiving of empty larrys
- #69, #70 Unit test failures on Windows
- #71 la.stack() Python 3.3 unit test failure
View
@@ -300,8 +300,18 @@ def align_raw(lar1, lar2, join='inner', cast=True):
list3.sort()
idx1, idx1_miss = listmap_fill(list1, list3, fill=0)
idx2, idx2_miss = listmap_fill(list2, list3, fill=0)
- x1 = x1.take(idx1, ax)
- x2 = x2.take(idx2, 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 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 miss1 == undefined:
miss1 = missing_marker(lar1)
@@ -332,7 +342,12 @@ def align_raw(lar1, lar2, join='inner', cast=True):
list3 = list(list1)
if list1 != list2:
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 miss2 == undefined:
miss2 = missing_marker(lar2)
@@ -354,7 +369,12 @@ def align_raw(lar1, lar2, join='inner', cast=True):
list3 = list(list2)
if list1 != list2:
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 miss1 == undefined:
miss1 = missing_marker(lar1)
View
@@ -401,6 +401,16 @@ def test_1d21(self):
ale(a1, d1, msg % 'left', original=y1)
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):
"Test 2d alignment of larrys"
@@ -516,6 +526,16 @@ def test_2d11(self):
ale(a1, d1, msg % 'left', original=y1)
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):
"Test align_axis on larrys"

0 comments on commit ae67e20

Please sign in to comment.