Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r66364:892ad8713af9 Date: 2013-08-27 16:43 +0100 http://bitbucket.org/pypy/pypy/changeset/892ad8713af9/
Log: merge diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py --- a/lib_pypy/_sqlite3.py +++ b/lib_pypy/_sqlite3.py @@ -1229,7 +1229,10 @@ if cvt is not None: param = cvt(param) - param = adapt(param) + try: + param = adapt(param) + except: + pass # And use previous value if param is None: rc = _lib.sqlite3_bind_null(self._statement, idx) diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py --- a/pypy/module/micronumpy/loop.py +++ b/pypy/module/micronumpy/loop.py @@ -370,7 +370,7 @@ def setitem_filter(arr, index, value): arr_iter = arr.create_iter() - index_iter = index.create_iter() + index_iter = index.create_iter(arr.get_shape()) value_iter = value.create_iter() shapelen = len(arr.get_shape()) index_dtype = index.get_dtype() diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -1922,6 +1922,28 @@ a = numpy.arange(10.).reshape((5, 2))[::2] assert (loads(dumps(a)) == a).all() + def test_string_filling(self): + import numpypy as numpy + a = numpy.empty((10,10), dtype='c1') + a.fill(12) + assert (a == '1').all() + + def test_boolean_indexing(self): + import numpypy as np + a = np.zeros((1, 3)) + b = np.array([True]) + + assert (a[b] == a).all() + + a[b] = 1. + + assert (a == [[1., 1., 1.]]).all() + + def test_boolean_array(self): + import numpypy as np + a = np.ndarray([1], dtype=bool) + assert a[0] == True + class AppTestMultiDim(BaseNumpyAppTest): def test_init(self): import numpypy @@ -2329,6 +2351,15 @@ a[a & 1 == 0] = 15 assert (a == [[15, 1], [15, 5], [15, 9]]).all() + def test_array_indexing_bool_specialcases(self): + from numpypy import arange, array + a = arange(6) + a[a > 3] = array([15]) + assert (a == [0, 1, 2, 3, 15, 15]).all() + a = arange(6).reshape(3, 2) + a[a & 1 == 1] = [] # here, Numpy sticks garbage into the array + assert a.shape == (3, 2) + def test_copy_kwarg(self): from numpypy import array x = array([1, 2, 3]) diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -1764,12 +1764,16 @@ arr.storage[i] = arg[i] return interp_boxes.W_StringBox(arr, 0, arr.dtype) - @jit.unroll_safe def store(self, arr, i, offset, box): assert isinstance(box, interp_boxes.W_StringBox) # XXX simplify to range(box.dtype.get_size()) ? + return self._store(arr.storage, i, offset, box) + + @jit.unroll_safe + def _store(self, storage, i, offset, box): + assert isinstance(box, interp_boxes.W_StringBox) for k in range(min(self.size, box.arr.size-offset)): - arr.storage[k + i] = box.arr.storage[k + offset] + storage[k + i] = box.arr.storage[k + offset] def read(self, arr, i, offset, dtype=None): if dtype is None: @@ -1859,6 +1863,11 @@ arr.storage[j] = '\x00' return interp_boxes.W_StringBox(arr, 0, arr.dtype) + def fill(self, storage, width, box, start, stop, offset): + from pypy.module.micronumpy.arrayimpl.concrete import ConcreteArrayNotOwning + for i in xrange(start, stop, width): + self._store(storage, i, offset, box) + NonNativeStringType = StringType class UnicodeType(BaseType, BaseStringType): diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py b/pypy/module/test_lib_pypy/test_sqlite3.py --- a/pypy/module/test_lib_pypy/test_sqlite3.py +++ b/pypy/module/test_lib_pypy/test_sqlite3.py @@ -228,3 +228,18 @@ cur = con.cursor() cur.execute(u'SELECT 1 as méil') assert cur.description[0][0] == u"méil".encode('utf-8') + +def test_adapter_exception(con): + def cast(obj): + raise ZeroDivisionError + + _sqlite3.register_adapter(int, cast) + try: + cur = con.cursor() + cur.execute("select ?", (4,)) + val = cur.fetchone()[0] + # Adapter error is ignored, and parameter is passed as is. + assert val == 4 + assert type(val) is int + finally: + del _sqlite3.adapters[(int, _sqlite3.PrepareProtocol)] _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit