[Scipy-svn] r6913 - in trunk/scipy/io: . matlab

scipy-svn@scip... scipy-svn@scip...
Sat Nov 20 00:20:12 CST 2010


Author: warren.weckesser
Date: 2010-11-20 00:20:11 -0600 (Sat, 20 Nov 2010)
New Revision: 6913

Modified:
   trunk/scipy/io/dumbdbm_patched.py
   trunk/scipy/io/matlab/mio.py
   trunk/scipy/io/matlab/mio4.py
   trunk/scipy/io/matlab/mio5.py
   trunk/scipy/io/mmio.py
Log:
ENH: io: update 'raise' statements

Modified: trunk/scipy/io/dumbdbm_patched.py
===================================================================
--- trunk/scipy/io/dumbdbm_patched.py	2010-11-20 05:57:51 UTC (rev 6912)
+++ trunk/scipy/io/dumbdbm_patched.py	2010-11-20 06:20:11 UTC (rev 6913)
@@ -110,7 +110,7 @@
 
     def __setitem__(self, key, val):
         if not isinstance(key, str) or not isinstance(val, str):
-            raise TypeError, "keys and values must be strings"
+            raise TypeError("keys and values must be strings")
         if not self._index.has_key(key):
             (pos, siz) = self._addval(val)
             self._addkey(key, (pos, siz))

Modified: trunk/scipy/io/matlab/mio.py
===================================================================
--- trunk/scipy/io/matlab/mio.py	2010-11-20 05:57:51 UTC (rev 6912)
+++ trunk/scipy/io/matlab/mio.py	2010-11-20 06:20:11 UTC (rev 6913)
@@ -214,8 +214,8 @@
         try:
             file_name.write(asbytes(''))
         except AttributeError:
-            raise IOError, 'Writer needs file name or writeable '\
-                           'file-like object'
+            raise IOError('Writer needs file name or writeable '
+                           'file-like object')
         file_stream = file_name
 
     if format == '4':

Modified: trunk/scipy/io/matlab/mio4.py
===================================================================
--- trunk/scipy/io/matlab/mio4.py	2010-11-20 05:57:51 UTC (rev 6912)
+++ trunk/scipy/io/matlab/mio4.py	2010-11-20 06:20:11 UTC (rev 6913)
@@ -105,7 +105,7 @@
         P,rest = divmod(rest,10)
         T = rest
         if O != 0:
-            raise ValueError, 'O in MOPT integer should be 0, wrong format?'
+            raise ValueError('O in MOPT integer should be 0, wrong format?')
         dims = (data['mrows'], data['ncols'])
         is_complex = data['imagf'] == 1
         dtype = self.dtypes[P]
@@ -128,7 +128,7 @@
             # no current processing (below) makes sense for sparse
             return self.read_sparse_array(hdr)
         else:
-            raise TypeError, 'No reader for class code %s' % mclass
+            raise TypeError('No reader for class code %s' % mclass)
         if process and self.squeeze_me:
             return squeeze_element(arr)
         return arr
@@ -400,9 +400,9 @@
             arr = arr.astype(dt.newbyteorder('='))
         dtt = dt.type
         if dtt is np.object_:
-            raise TypeError, 'Cannot save object arrays in Mat4'
+            raise TypeError('Cannot save object arrays in Mat4')
         elif dtt is np.void:
-            raise TypeError, 'Cannot save void type arrays'
+            raise TypeError('Cannot save void type arrays')
         elif dtt in (np.unicode_, np.string_):
             self.write_char(arr, name)
             return

Modified: trunk/scipy/io/matlab/mio5.py
===================================================================
--- trunk/scipy/io/matlab/mio5.py	2010-11-20 05:57:51 UTC (rev 6912)
+++ trunk/scipy/io/matlab/mio5.py	2010-11-20 06:20:11 UTC (rev 6913)
@@ -229,8 +229,7 @@
         else:
             self._matrix_reader.set_stream(self.mat_stream)
         if not mdtype == miMATRIX:
-            raise TypeError, \
-                'Expecting miMATRIX type here, got %d' %  mdtype
+            raise TypeError('Expecting miMATRIX type here, got %d' %  mdtype)
         header = self._matrix_reader.read_header()
         return header, next_pos
             

Modified: trunk/scipy/io/mmio.py
===================================================================
--- trunk/scipy/io/mmio.py	2010-11-20 05:57:51 UTC (rev 6912)
+++ trunk/scipy/io/mmio.py	2010-11-20 06:20:11 UTC (rev 6913)
@@ -127,8 +127,8 @@
     @classmethod
     def _validate_format(self, format):
         if format not in self.FORMAT_VALUES:
-            raise ValueError,'unknown format type %s, must be one of %s'% \
-              (`format`, `self.FORMAT_VALUES`)
+            raise ValueError('unknown format type %s, must be one of %s' %
+                                (format, self.FORMAT_VALUES))
 
     # field values
     FIELD_INTEGER = 'integer'
@@ -140,8 +140,8 @@
     @classmethod
     def _validate_field(self, field):
         if field not in self.FIELD_VALUES:
-            raise ValueError,'unknown field type %s, must be one of %s'% \
-              (`field`, `self.FIELD_VALUES`)
+            raise ValueError('unknown field type %s, must be one of %s' %
+                                (field, self.FIELD_VALUES))
 
     # symmetry values
     SYMMETRY_GENERAL        = 'general'
@@ -154,8 +154,8 @@
     @classmethod
     def _validate_symmetry(self, symmetry):
         if symmetry not in self.SYMMETRY_VALUES:
-            raise ValueError,'unknown symmetry type %s, must be one of %s'% \
-              (`symmetry`, `self.SYMMETRY_VALUES`)
+            raise ValueError('unknown symmetry type %s, must be one of %s' %
+                                (symmetry, self.SYMMETRY_VALUES))
 
     DTYPES_BY_FIELD = {
       FIELD_INTEGER: 'i',
@@ -183,7 +183,7 @@
             mmid, matrix, format, field, symmetry  = \
               [asstr(part.strip().lower()) for part in line.split()]
             if not mmid.startswith('%%matrixmarket'):
-                raise ValueError,'source is not in Matrix Market format'
+                raise ValueError('source is not in Matrix Market format')
 
             assert matrix == 'matrix',`line`
 
@@ -322,9 +322,8 @@
         invalid_keys = set(kwargs.keys()) - set(public_attrs)
 
         if invalid_keys:
-            raise ValueError, \
-              'found %s invalid keyword arguments, please only use %s' % \
-              (`tuple(invalid_keys)`, `public_attrs`)
+            raise ValueError('found %s invalid keyword arguments, please only use %s' %
+                                (tuple(invalid_keys), public_attrs))
 
         for attr in attrs: setattr(self, attr, kwargs.get(attr[1:], None))
 
@@ -465,7 +464,7 @@
 
             a = coo_matrix((V, (I, J)), shape=(rows, cols), dtype=dtype)
         else:
-            raise NotImplementedError,`format`
+            raise NotImplementedError(format)
 
         return a
 
@@ -476,7 +475,7 @@
             rep = self.FORMAT_ARRAY
             a = asarray(a)
             if len(a.shape) != 2:
-                raise ValueError, 'expected matrix'
+                raise ValueError('expected matrix')
             rows,cols = a.shape
             entries = rows*cols
 
@@ -494,7 +493,7 @@
         else:
             from scipy.sparse import spmatrix
             if not isinstance(a,spmatrix):
-                raise ValueError,'unknown matrix type ' + `type(a)`
+                raise ValueError('unknown matrix type: %s' % type(a))
             rep = 'coordinate'
             rows, cols = a.shape
             entries = a.getnnz()
@@ -569,10 +568,10 @@
                             stream.write(asbytes(template % (real(aij),imag(aij))))
 
             elif field == self.FIELD_PATTERN:
-                raise ValueError,'pattern type inconsisted with dense format'
+                raise ValueError('pattern type inconsisted with dense format')
 
             else:
-                raise TypeError,'Unknown field type %s'% `field`
+                raise TypeError('Unknown field type %s' % field)
 
         # write sparse format
         else:
@@ -594,7 +593,7 @@
             elif field == self.FIELD_COMPLEX:
                 IJV = vstack((coo.row, coo.col, coo.data.real, coo.data.imag)).T
             else:
-                raise TypeError('Unknown field type %s' % `field`)
+                raise TypeError('Unknown field type %s' % field)
 
             IJV[:,:2] += 1 # change base 0 -> base 1
 



More information about the Scipy-svn mailing list