[Scipy-svn] r6541 - in branches/0.8.x/scipy/io: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Jun 18 11:36:37 EDT 2010


Author: rgommers
Date: 2010-06-18 10:36:37 -0500 (Fri, 18 Jun 2010)
New Revision: 6541

Modified:
   branches/0.8.x/scipy/io/netcdf.py
   branches/0.8.x/scipy/io/tests/test_netcdf.py
Log:
BUG: netcdf_file.flush() was trying to access non-existing attribute.

Backport of r6540.

Modified: branches/0.8.x/scipy/io/netcdf.py
===================================================================
--- branches/0.8.x/scipy/io/netcdf.py	2010-06-18 15:34:00 UTC (rev 6540)
+++ branches/0.8.x/scipy/io/netcdf.py	2010-06-18 15:36:37 UTC (rev 6541)
@@ -4,7 +4,7 @@
 This module implements the Scientific.IO.NetCDF API to read and create
 NetCDF files. The same API is also used in the PyNIO and pynetcdf
 modules, allowing these modules to be used interchangebly when working
-with NetCDF files. The major advantage of ``scipy.io.netcdf`` over other 
+with NetCDF files. The major advantage of ``scipy.io.netcdf`` over other
 modules is that it doesn't require the code to be linked to the NetCDF
 libraries as the other modules do.
 
@@ -28,7 +28,7 @@
 and they are stored at the end of the file per record, ie
 
     A[0], B[0], ..., A[1], B[1], ..., etc,
-    
+
 so that new data can be appended to the file without changing its original
 structure. Non-record data are padded to a 4n bytes boundary. Record data
 are also padded, unless there is exactly one record variable in the file,
@@ -86,7 +86,7 @@
 from numpy import little_endian as LITTLE_ENDIAN
 
 
-ABSENT       = '\x00\x00\x00\x00\x00\x00\x00\x00' 
+ABSENT       = '\x00\x00\x00\x00\x00\x00\x00\x00'
 ZERO         = '\x00\x00\x00\x00'
 NC_BYTE      = '\x00\x00\x00\x01'
 NC_CHAR      = '\x00\x00\x00\x02'
@@ -193,7 +193,7 @@
     def close(self):
         if not self.fp.closed:
             try:
-                self.flush()
+               self.flush()
             finally:
                 self.fp.close()
     __del__ = close
@@ -203,7 +203,7 @@
         self._dims.append(name)
 
     def createVariable(self, name, type, dimensions):
-        shape = tuple([self.dimensions[dim] for dim in dimensions]) 
+        shape = tuple([self.dimensions[dim] for dim in dimensions])
         shape_ = tuple([dim or 0 for dim in shape])  # replace None with 0 for numpy
 
         if isinstance(type, basestring): type = dtype(type)
@@ -216,7 +216,7 @@
         return self.variables[name]
 
     def flush(self):
-        if self.mode is 'w':
+        if hasattr(self, 'mode') and self.mode is 'w':
             self._write()
     sync = flush
 
@@ -266,7 +266,7 @@
             self.fp.write(NC_VARIABLE)
             self._pack_int(len(self.variables))
 
-            # Sort variables non-recs first, then recs. We use a DSU 
+            # Sort variables non-recs first, then recs. We use a DSU
             # since some people use pupynere with Python 2.3.x.
             deco = [ (v._shape and not v.isrec, k) for (k, v) in self.variables.items() ]
             deco.sort()
@@ -321,7 +321,7 @@
 
     def _write_var_data(self, name):
         var = self.variables[name]
-        
+
         # Set begin in file header.
         the_beguine = self.fp.tell()
         self.fp.seek(var._begin)
@@ -330,7 +330,7 @@
 
         # Write data.
         if not var.isrec:
-            self.fp.write(var.data.tostring())    
+            self.fp.write(var.data.tostring())
             count = var.data.size * var.data.itemsize
             self.fp.write('0' * (var._vsize - count))
         else:  # record variable
@@ -379,7 +379,7 @@
             dtype_ = '>%s' % typecode
             if size > 1: dtype_ += str(size)
 
-        values = asarray(values, dtype=dtype_) 
+        values = asarray(values, dtype=dtype_)
 
         self.fp.write(nc_type)
 
@@ -527,7 +527,7 @@
         dimensions = []
         shape = []
         dims = self._unpack_int()
-        
+
         for i in range(dims):
             dimid = self._unpack_int()
             dimname = self._dims[dimid]
@@ -565,7 +565,7 @@
             values = fromstring(values, dtype='>%s%d' % (typecode, size))
             if values.shape == (1,): values = values[0]
         else:
-            values = values.rstrip('\x00') 
+            values = values.rstrip('\x00')
         return values
 
     def _pack_begin(self, begin):

Modified: branches/0.8.x/scipy/io/tests/test_netcdf.py
===================================================================
--- branches/0.8.x/scipy/io/tests/test_netcdf.py	2010-06-18 15:34:00 UTC (rev 6540)
+++ branches/0.8.x/scipy/io/tests/test_netcdf.py	2010-06-18 15:36:37 UTC (rev 6541)
@@ -38,8 +38,8 @@
     yield assert_equal, str(time.units), 'days since 2008-01-01'
     yield assert_equal, time.shape, (N_EG_ELS,)
     yield assert_equal, time[-1], N_EG_ELS-1
-    
 
+
 def test_read_write_files():
     # test round trip for example file
     cwd = os.getcwd()
@@ -118,4 +118,4 @@
     for fname in glob(pjoin(TEST_DATA_PATH, '*.nc')):
         f = netcdf_file(fname, 'r')
         f = netcdf_file(fname, 'r', mmap=False)
-    
+




More information about the Scipy-svn mailing list