[Numpy-svn] r5115 - in trunk/numpy: . core/src core/tests

numpy-svn@scip... numpy-svn@scip...
Wed Apr 30 17:07:19 CDT 2008


Author: stefan
Date: 2008-04-30 17:06:41 -0500 (Wed, 30 Apr 2008)
New Revision: 5115

Modified:
   trunk/numpy/add_newdocs.py
   trunk/numpy/core/src/arraymethods.c
   trunk/numpy/core/tests/test_multiarray.py
Log:
For x.view, change dtype into keyword argument.


Modified: trunk/numpy/add_newdocs.py
===================================================================
--- trunk/numpy/add_newdocs.py	2008-04-30 19:36:42 UTC (rev 5114)
+++ trunk/numpy/add_newdocs.py	2008-04-30 22:06:41 UTC (rev 5115)
@@ -2198,15 +2198,15 @@
 
 
 add_newdoc('numpy.core.multiarray', 'ndarray', ('view',
-    """a.view(type)
+    """a.view(dtype=None)
 
     New view of array with the same data.
 
     Parameters
     ----------
-    type
-        Either a new sub-type object or a data-descriptor object
-    
+    dtype : sub-type or data-descriptor
+        Data-type of the returned view.
+
     """))
 
 add_newdoc('numpy.core.umath','geterrobj',

Modified: trunk/numpy/core/src/arraymethods.c
===================================================================
--- trunk/numpy/core/src/arraymethods.c	2008-04-30 19:36:42 UTC (rev 5114)
+++ trunk/numpy/core/src/arraymethods.c	2008-04-30 22:06:41 UTC (rev 5115)
@@ -101,12 +101,14 @@
 }
 
 static PyObject *
-array_view(PyArrayObject *self, PyObject *args)
+array_view(PyArrayObject *self, PyObject *args, PyObject *kwds)
 {
     PyObject *otype=NULL;
     PyArray_Descr *type=NULL;
 
-    if (!PyArg_ParseTuple(args, "|O", &otype)) return NULL;
+    static char *kwlist[] = {"dtype", NULL};
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &otype))
+        return NULL;
 
     if (otype) {
         if (PyType_Check(otype) &&                      \
@@ -1994,7 +1996,7 @@
     {"var", (PyCFunction)array_variance,
          METH_VARARGS | METH_KEYWORDS, NULL},
     {"view", (PyCFunction)array_view,
-         METH_VARARGS, NULL},
+         METH_VARARGS | METH_KEYWORDS, NULL},
     {NULL, NULL}           /* sentinel */
 };
 

Modified: trunk/numpy/core/tests/test_multiarray.py
===================================================================
--- trunk/numpy/core/tests/test_multiarray.py	2008-04-30 19:36:42 UTC (rev 5114)
+++ trunk/numpy/core/tests/test_multiarray.py	2008-04-30 22:06:41 UTC (rev 5115)
@@ -833,6 +833,16 @@
         dt.names = ['p','q']
         assert_equal(dt.names,['p','q'])
 
+class TestView(NumpyTestCase):
+    def test_basic(self):
+        x = np.array([(1,2,3,4),(5,6,7,8)],dtype=[('r',np.int8),('g',np.int8),
+                                                  ('b',np.int8),('a',np.int8)])
+        y = x.view(dtype=np.int32)
+        z = x.view(np.int32)
+        assert_array_equal(y,z)
+        assert_array_equal(y, [67305985, 134678021])
+
+
 # Import tests without matching module names
 set_local_path()
 from test_unicode import *



More information about the Numpy-svn mailing list