[Numpy-svn] r3253 - trunk/numpy/core

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Oct 5 01:52:47 CDT 2006


Author: oliphant
Date: 2006-10-05 01:52:38 -0500 (Thu, 05 Oct 2006)
New Revision: 3253

Modified:
   trunk/numpy/core/records.py
Log:
Fix so that rec.array copies by default.

Modified: trunk/numpy/core/records.py
===================================================================
--- trunk/numpy/core/records.py	2006-10-05 06:40:42 UTC (rev 3252)
+++ trunk/numpy/core/records.py	2006-10-05 06:52:38 UTC (rev 3253)
@@ -476,7 +476,7 @@
     return _array
 
 def array(obj, dtype=None, shape=None, offset=0, strides=None, formats=None,
-          names=None, titles=None, aligned=False, byteorder=None):
+          names=None, titles=None, aligned=False, byteorder=None, copy=True):
     """Construct a record array from a wide-variety of objects.
     """
 
@@ -513,18 +513,29 @@
             return fromarrays(obj, dtype=dtype, shape=shape, **kwds)
 
     elif isinstance(obj, recarray):
-        new = obj.copy()
-        if dtype is not None:
-            new.dtype = dtype
+        copied = 0
+        if dtype is not None and (new.dtype != dtype):
+            new = obj.astype(dtype)
+            copied = 1
+        else:
+            new = obj
+        if copy and not copied:
+            new = new.copy()
         return new
 
     elif isinstance(obj, file):
         return fromfile(obj, dtype=dtype, shape=shape, offset=offset)
 
     elif isinstance(obj, sb.ndarray):
+        copied = 0
         if dtype is not None and (obj.dtype != dtype):
-            obj = obj.view(dtype)
-        res = obj.view(recarray)
+            new = obj.astype(dtype)
+            copied = 1
+        else:
+            new = obj
+        if copy and not copied:
+            new = new.copy()
+        res = new.view(recarray)
         if issubclass(res.dtype.type, nt.void):
             res.dtype = sb.dtype((record, res.dtype))
         return res



More information about the Numpy-svn mailing list