Skip to content

Commit

Permalink
Merge pull request scipy#7908 from larsoner/netcdf
Browse files Browse the repository at this point in the history
FIX: Avoid bad __del__ (close) behavior
  • Loading branch information
rgommers authored Sep 22, 2017
2 parents 04759f9 + 4f42d42 commit ac590a8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions scipy/io/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def __setattr__(self, attr, value):

def close(self):
"""Closes the NetCDF file."""
if not self.fp.closed:
if hasattr(self, 'fp') and not self.fp.closed:
try:
self.flush()
finally:
Expand Down Expand Up @@ -511,8 +511,8 @@ def _write_var_data(self, name):
# Handle rec vars with shape[0] < nrecs.
if self._recs > len(var.data):
shape = (self._recs,) + var.data.shape[1:]
# Resize in-place does not always work since
# the array might not be single-segment
# Resize in-place does not always work since
# the array might not be single-segment
try:
var.data.resize(shape)
except ValueError:
Expand Down Expand Up @@ -987,8 +987,8 @@ def __setitem__(self, index, data):
recs = rec_index + 1
if recs > len(self.data):
shape = (recs,) + self._shape[1:]
# Resize in-place does not always work since
# the array might not be single-segment
# Resize in-place does not always work since
# the array might not be single-segment
try:
self.data.resize(shape)
except ValueError:
Expand Down

0 comments on commit ac590a8

Please sign in to comment.