[pypy-commit] pypy default: numpy has opinions. It has it's own opinion what's a sequence and it's own
fijal
noreply at buildbot.pypy.org
Wed Oct 31 15:11:04 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r58638:de6cd9aa69b0
Date: 2012-10-31 16:09 +0200
http://bitbucket.org/pypy/pypy/changeset/de6cd9aa69b0/
Log: numpy has opinions. It has it's own opinion what's a sequence and
it's own opinion what's an int. Deal with that
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
@@ -3,6 +3,11 @@
from pypy.tool.pairtype import extendabletype
from pypy.module.micronumpy.support import calc_strides
+def issequence_w(space, w_obj):
+ return (space.isinstance_w(w_obj, space.w_tuple) or
+ space.isinstance_w(w_obj, space.w_list) or
+ isinstance(w_obj, W_NDimArray))
+
class ArrayArgumentException(Exception):
pass
@@ -44,7 +49,7 @@
if isinstance(w_obj, W_NDimArray):
return w_obj
- elif space.issequence_w(w_obj):
+ elif issequence_w(space, w_obj):
# Convert to array.
return array(space, w_obj, w_order=None)
else:
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -3,7 +3,7 @@
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
from pypy.module.micronumpy.base import W_NDimArray, convert_to_array,\
- ArrayArgumentException
+ ArrayArgumentException, issequence_w
from pypy.module.micronumpy import interp_dtype, interp_ufuncs, interp_boxes
from pypy.module.micronumpy.strides import find_shape_and_elems,\
get_shape_from_iterable, to_coords, shape_agreement
@@ -644,7 +644,7 @@
@unwrap_spec(ndmin=int, copy=bool, subok=bool)
def array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False,
ndmin=0):
- if not space.issequence_w(w_object):
+ if not issequence_w(space, w_object):
if space.is_none(w_dtype):
w_dtype = interp_ufuncs.find_dtype_for_scalar(space, w_object)
dtype = space.interp_w(interp_dtype.W_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
@@ -2272,6 +2272,11 @@
raises(TypeError, a, 'sum')
raises(TypeError, 'a+a')
+ def test_string_scalar(self):
+ from _numpypy import array
+ a = array('ffff')
+ assert a.shape == ()
+
def test_flexible_repr(self):
# import overrides str(), repr() for array
from numpypy.core import arrayprint
More information about the pypy-commit
mailing list