Skip to content

Commit

Permalink
Merge pull request #141 from WarrenWeckesser/ticket1202
Browse files Browse the repository at this point in the history
BUG: io: add work-around in netcdf.py for the bug in numpy that is the c...
  • Loading branch information
WarrenWeckesser committed Jan 29, 2012
2 parents 39001f6 + 3cf1cb0 commit b5838b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scipy/io/netcdf.py
Expand Up @@ -801,6 +801,14 @@ def assignValue(self, value):
netcdf variable.
"""
if not self.data.flags.writeable:
# Work-around for a bug in NumPy. Calling itemset() on a read-only
# memory-mapped array causes a seg. fault.
# See NumPy ticket #1622, and SciPy ticket #1202.
# This check for `writeable` can be removed when the oldest version
# of numpy still supported by scipy contains the fix for #1622.
raise RuntimeError("variable is not writeable")

self.data.itemset(value)

def typecode(self):
Expand Down
8 changes: 8 additions & 0 deletions scipy/io/tests/test_netcdf.py
Expand Up @@ -124,6 +124,14 @@ def test_read_example_data():
f = netcdf_file(fname, 'r')
f = netcdf_file(fname, 'r', mmap=False)

def test_itemset_no_segfault_on_readonly():
# Regression test for ticket #1202.
# Open the test file in read-only mode.
filename = pjoin(TEST_DATA_PATH, 'example_1.nc')
f = netcdf_file(filename, 'r')
time_var = f.variables['time']
# time_var.assignValue(42) should raise a RuntimeError--not seg. fault!
assert_raises(RuntimeError, time_var.assignValue, 42)

def test_write_invalid_dtype():
dtypes = ['int64', 'uint64']
Expand Down

0 comments on commit b5838b9

Please sign in to comment.