Author: Brian Kearns <[email protected]>
Branch:
Changeset: r68513:ba9a05a2fcc4
Date: 2013-12-20 14:52 -0500
http://bitbucket.org/pypy/pypy/changeset/ba9a05a2fcc4/
Log: fix initialization of scalar flexible types
diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py
--- a/pypy/module/micronumpy/base.py
+++ b/pypy/module/micronumpy/base.py
@@ -38,7 +38,7 @@
from pypy.module.micronumpy.arrayimpl import concrete, scalar
if not shape:
- w_val = dtype.base.coerce(space, space.wrap(0))
+ w_val = dtype.base.coerce(space, None)
impl = scalar.Scalar(dtype.base, w_val)
else:
strides, backstrides = calc_strides(shape, dtype.base, order)
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
@@ -354,7 +354,10 @@
# And check that changes stick.
a[13] = 5.3
assert a[13] == 5.3
+ assert zeros(()) == 0
assert zeros(()).shape == ()
+ assert zeros((), dtype='S') == ''
+ assert zeros((), dtype='S').shape == ()
def test_empty_like(self):
import numpy as np
@@ -3046,6 +3049,10 @@
def test_zeros(self):
from numpypy import zeros
+ a = zeros((), dtype=[('x', int), ('y', float)])
+ assert a[()]['x'] == 0
+ assert a[()]['y'] == 0
+ assert a.shape == ()
a = zeros(2, dtype=[('x', int), ('y', float)])
raises(IndexError, 'a[0]["xyz"]')
assert a[0]['x'] == 0
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
@@ -1620,6 +1620,8 @@
from pypy.module.micronumpy.interp_dtype import new_string_dtype
if isinstance(w_item, interp_boxes.W_StringBox):
return w_item
+ if w_item is None:
+ w_item = space.wrap('')
arg = space.str_w(space.str(w_item))
arr = VoidBoxStorage(len(arg), new_string_dtype(space, len(arg)))
for i in range(len(arg)):
@@ -1819,6 +1821,8 @@
def coerce(self, space, dtype, w_item):
if isinstance(w_item, interp_boxes.W_VoidBox):
return w_item
+ if w_item is None:
+ w_item = space.newtuple([None] * len(dtype.fields))
# we treat every sequence as sequence, no special support
# for arrays
if not space.issequence_w(w_item):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit