Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r67940:99f9d0c4eb89 Date: 2013-11-10 21:30 -0500 http://bitbucket.org/pypy/pypy/changeset/99f9d0c4eb89/
Log: fix a numpy scalar indexing case diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py --- a/pypy/module/micronumpy/interp_boxes.py +++ b/pypy/module/micronumpy/interp_boxes.py @@ -126,6 +126,15 @@ def item(self, space): return self.get_dtype(space).itemtype.to_builtin_type(space, self) + def descr_getitem(self, space, w_item): + from pypy.module.micronumpy.base import convert_to_array + if space.is_w(w_item, space.w_Ellipsis) or \ + (space.isinstance_w(w_item, space.w_tuple) and + space.len_w(w_item) == 0): + return convert_to_array(space, self) + raise OperationError(space.w_IndexError, space.wrap( + "invalid index to scalar variable")) + def descr_str(self, space): return space.wrap(self.get_dtype(space).itemtype.str_format(self)) @@ -467,6 +476,7 @@ __new__ = interp2app(W_GenericBox.descr__new__.im_func), + __getitem__ = interp2app(W_GenericBox.descr_getitem), __str__ = interp2app(W_GenericBox.descr_str), __repr__ = interp2app(W_GenericBox.descr_str), __format__ = interp2app(W_GenericBox.descr_format), diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -83,6 +83,15 @@ assert value.ndim == 0 assert value.T is value + def test_indexing(self): + import numpy as np + v = np.int32(2) + for b in [v[()], v[...]]: + assert isinstance(b, np.ndarray) + assert b.shape == () + assert b == v + raises(IndexError, "v['blah']") + def test_complex_scalar_complex_cast(self): import numpy as np for tp in [np.csingle, np.cdouble, np.clongdouble]: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit