Skip to content

Commit

Permalink
BUG: io: add work-around in netcdf.py for the bug in numpy that is th…
Browse files Browse the repository at this point in the history
…e cause of the problem reported in ticket #1202
  • Loading branch information
WarrenWeckesser authored and rgommers committed Feb 5, 2012
1 parent 9b71b65 commit 0308a46
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 0308a46

Please sign in to comment.