Author: Alex Gaynor <alex.gay...@gmail.com> Branch: numpy-dtype-alt Changeset: r46727:f9d64b81ab65 Date: 2011-08-23 06:25 -0500 http://bitbucket.org/pypy/pypy/changeset/f9d64b81ab65/
Log: expose dtype attribute on arrays, and add it to the repr 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 @@ -221,19 +221,28 @@ def get_concrete(self): raise NotImplementedError - def descr_copy(self, space): - return space.call_function(space.gettypefor(BaseArray), self, self.find_dtype()) + def descr_get_dtype(self, space): + return space.wrap(self.find_dtype()) def descr_get_shape(self, space): return space.newtuple([self.descr_len(space)]) + def descr_copy(self, space): + return space.call_function(space.gettypefor(BaseArray), self, self.find_dtype()) + def descr_len(self, space): return self.get_concrete().descr_len(space) def descr_repr(self, space): # Simple implementation so that we can see the array. Needs work. concrete = self.get_concrete() - return space.wrap("array([" + ", ".join(concrete._getnums(False)) + "])") + res = "array([" + ", ".join(concrete._getnums(False)) + "]" + dtype = concrete.find_dtype() + if (dtype is not space.fromcache(interp_dtype.W_Float64Dtype) and + dtype is not space.fromcache(interp_dtype.W_Int64Dtype)): + res += ", dtype=" + dtype.name + res += ")" + return space.wrap(res) def descr_str(self, space): # Simple implementation so that we can see the array. Needs work. @@ -574,8 +583,6 @@ 'numarray', __new__ = interp2app(BaseArray.descr__new__.im_func), - copy = interp2app(BaseArray.descr_copy), - shape = GetSetProperty(BaseArray.descr_get_shape), __len__ = interp2app(BaseArray.descr_len), __getitem__ = interp2app(BaseArray.descr_getitem), @@ -599,6 +606,9 @@ __repr__ = interp2app(BaseArray.descr_repr), __str__ = interp2app(BaseArray.descr_str), + dtype = GetSetProperty(BaseArray.descr_get_dtype), + shape = GetSetProperty(BaseArray.descr_get_shape), + mean = interp2app(BaseArray.descr_mean), sum = interp2app(BaseArray.descr_sum), prod = interp2app(BaseArray.descr_prod), @@ -609,4 +619,6 @@ all = interp2app(BaseArray.descr_all), any = interp2app(BaseArray.descr_any), dot = interp2app(BaseArray.descr_dot), + + copy = interp2app(BaseArray.descr_copy), ) diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -21,6 +21,12 @@ assert dtype(long).num == 9 assert dtype(float).num == 12 + def test_array_dtype_attr(self): + from numpy import array, dtype + + a = array(range(5), long) + assert a.dtype is dtype(long) + def test_repr_str(self): from numpy import 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 @@ -59,7 +59,7 @@ a = array(range(5), long) assert repr(a) == "array([0, 1, 2, 3, 4])" a = array([True, False, True, False], "?") - assert repr(a) == "array([True, False, True, False])" + assert repr(a) == "array([True, False, True, False], dtype=bool)" def test_repr_slice(self): from numpy import array, zeros _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit