Skip to content
This repository

Bug in #232

wants to merge 1 commit into from

3 participants

Marc Honnorat Pauli Virtanen Ralf Gommers
Marc Honnorat


There is a bug in when calling sync() or flush(). When writing to disk, the whole Netcdf structure is written, but the file is not rewound. Therefore, the second call to _write() (which can happen when closing the file) just append a second version of the structure after the first one.

This patch just adds a seek(0) before any writing operation.

Pauli Virtanen
pv commented May 29, 2012

Can you add a regression test --- i.e., write a small test program that fails previously, but works after this bugfix?

Marc Honnorat
#!/usr/bin/env python
import os
import as cdf

f = cdf.netcdf_file('', mode='w')
x = f.createDimension('x',4)
v = f.createVariable('v', 'i2', ['x'])

v[:] = 1
print "First read  : %d" % os.path.getsize('')

v[:] = 2
print "Second read : %d" % os.path.getsize('')

print "Last read   : %d" % os.path.getsize('')

Before the fix:

First read  : 80
Second read : 168
Last read   : 264

After the fix:

First read  : 80
Second read : 88
Last read   : 88
Ralf Gommers

I converted the above to a regression test. It actually didn't work with numpy 1.7.0-dev (because of, so I fixed the dtype parameter handling as well. Please check if that looks OK: rgommers@76a983e

Ralf Gommers

I merged this PR and my fix/tests in 7ac86ab, in order to get it in for 0.11.

Ralf Gommers

Thanks for your contribution Marc.

Ralf Gommers rgommers closed this June 09, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 23, 2012
Marc Honnorat BUG: Rewind file object before writing Netcdf. 7294357
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 0 deletions. Show diff stats Hide diff stats

  1. 1  scipy/io/
1  scipy/io/
@@ -305,6 +305,7 @@ def flush(self):
305 305
     sync = flush
306 306
307 307
     def _write(self):
308 309
309 310
         self.fp.write(array(self.version_byte, '>b').tostring())
310 311

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.