Commits

mattip  committed 0be2466

implement, test more of numpy c api

  • Participants
  • Parent commits b355653

Comments (0)

Files changed (2)

File pypy/module/cpyext/ndarrayobject.py

          only used if the array is constructed that way. Almost always this
          parameter is NULL.
     """
-    if min_depth !=0 or max_depth != 0:
-        raise OperationError(space.w_NotImplementedError, space.wrap(
-            '_PyArray_FromAny called with not-implemented min_dpeth or max_depth argument'))
     if requirements not in (0, NPY_DEFAULT):
         raise OperationError(space.w_NotImplementedError, space.wrap(
             '_PyArray_FromAny called with not-implemented requirements argument'))
     w_array = array(space, w_obj, w_dtype=w_dtype, copy=False)
-    if w_array.is_scalar():
+    if min_depth !=0 and len(w_array.get_shape()) < min_depth:
+        raise OperationError(space.w_ValueError, space.wrap(
+            'object of too small depth for desired array'))
+    elif max_depth !=0 and len(w_array.get_shape()) > max_depth:
+        raise OperationError(space.w_ValueError, space.wrap(
+            'object of too deep for desired array'))
+    elif w_array.is_scalar():
         # since PyArray_DATA() fails on scalars, create a 1D array and set empty
         # shape. So the following combination works for *reading* scalars:
         #     PyObject *arr = PyArray_FromAny(obj);

File pypy/module/cpyext/test/test_ndarrayobject.py

     def test_FromAny(self, space, api):
         a = array(space, [10, 5, 3])
         assert api._PyArray_FromAny(a, NULL, 0, 0, 0, NULL) is a
-        self.raises(space, api, NotImplementedError, api._PyArray_FromAny,
-                    a, NULL, 0, 3, 0, NULL)
+        assert api._PyArray_FromAny(a, NULL, 1, 4, 0, NULL) is a
+        self.raises(space, api, ValueError, api._PyArray_FromAny,
+                    a, NULL, 4, 5, 0, NULL)
 
     def test_FromObject(self, space, api):
         a = array(space, [10, 5, 3])
         assert api._PyArray_FromObject(a, a.get_dtype().num, 0, 0) is a
-        exc = self.raises(space, api, NotImplementedError, api._PyArray_FromObject,
-                    a, 11, 0, 3)
-        assert exc.errorstr(space).find('FromObject') >= 0
+        exc = self.raises(space, api, ValueError, api._PyArray_FromObject,
+                    a, 11, 4, 5)
+        assert exc.errorstr(space).find('desired') >= 0
 
     def test_list_from_fixedptr(self, space, api):
         A = lltype.GcArray(lltype.Float)