diff options
author | Travis Oliphant <oliphant@enthought.com> | 2009-12-02 21:25:58 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2009-12-02 21:25:58 +0000 |
commit | 49d9ff44f860ee94c500294ead71f63f18d19ae9 (patch) | |
tree | b3b0dce0fee8df4c0660d2ca8ff1146e28322acf /numpy | |
parent | 55f0dfc4620cf52a47e7e1b1e9ad937c803c21b9 (diff) | |
download | numpy-49d9ff44f860ee94c500294ead71f63f18d19ae9.tar.gz |
TST: Add regression test for Ticket #1299 and clean-up test for non-buffered structured array bug.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_regression.py | 21 | ||||
-rw-r--r-- | numpy/core/tests/test_umath.py | 17 |
2 files changed, 30 insertions, 8 deletions
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 87c451b4e..debb427ea 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1208,5 +1208,26 @@ class TestRegression(TestCase): # big-endian machine assert_equal(x, np.fromstring(y.tostring(), dtype='<c8')) + def test_structured_arrays_with_objects1(self): + """Ticket #1299""" + stra = 'aaaa' + strb = 'bbbb' + x = np.array([[(0,stra),(1,strb)]], 'i8,O') + x[x.nonzero()] = x.ravel()[:1] + assert x[0,1] == x[0,0] + + def test_structured_arrays_with_objects2(self): + """Ticket #1299 second test""" + stra = 'aaaa' + strb = 'bbbb' + numb = sys.getrefcount(strb) + numa = sys.getrefcount(stra) + x = np.array([[(0,stra),(1,strb)]], 'i8,O') + x[x.nonzero()] = x.ravel()[:1] + assert sys.getrefcount(strb) == numb + assert sys.getrefcount(stra) == numa + 2 + + + if __name__ == "__main__": run_module_suite() diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 9d2fe1174..584672f30 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -930,7 +930,7 @@ def test_pos_nan(): assert np.signbit(np.nan) == 0 def test_reduceat(): - """Test bug in reduceat with structured arrays copied for speed.""" + """Test bug in reduceat when structured arrays are not copied.""" db = np.dtype([('name', 'S11'),('time', np.int64), ('value', np.float32)]) a = np.empty([100], dtype=db) a['name'] = 'Simple' @@ -946,16 +946,17 @@ def test_reduceat(): h2.append(np.add.reduce(a['value'][val1:])) h2 = np.array(h2) - # test buffered + # test buffered -- this should work + h1 = np.add.reduceat(a['value'], indx) + assert_array_almost_equal(h1, h2) + + # This is when the error occurs. + # test no buffer res = np.setbufsize(32) h1 = np.add.reduceat(a['value'], indx) + np.setbufsize(np.UFUNC_BUFSIZE_DEFAULT) assert_array_almost_equal(h1, h2) - - # test nobuffer - np.setbufsize(res) - h1 = np.add.reduceat(a['value'], indx) - assert_array_almost_equal(h1, h2) - + if __name__ == "__main__": run_module_suite() |