Skip to content

Commit

Permalink
fix(csvfile): correction to read_csv args, close file handle
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Oct 16, 2022
1 parent 2eeefd4 commit d1dbe76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions autotest/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ def test_output(tmpdir, example_data_path):

bud = ml.oc.output.budget()
budcsv = ml.oc.output.budgetcsv()
assert budcsv.file.closed
hds = ml.oc.output.head()
lst = ml.oc.output.list()

Expand Down
28 changes: 14 additions & 14 deletions flopy/utils/observationfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,20 +509,20 @@ def __init__(
self, csvfile, delimiter=",", deletechars="", replace_space=""
):

self.file = open(csvfile, "r")
self.delimiter = delimiter
self.deletechars = deletechars
self.replace_space = replace_space

# read header line
line = self.file.readline()
self._header = line.rstrip().split(delimiter)
self.floattype = "f8"
self.dtype = _build_dtype(self._header, self.floattype)

self.data = self.read_csv(
self.file, self.dtype, delimiter, replace_space
)
with open(csvfile, "r") as self.file:
self.delimiter = delimiter
self.deletechars = deletechars
self.replace_space = replace_space

# read header line
line = self.file.readline()
self._header = line.rstrip().split(delimiter)
self.floattype = "f8"
self.dtype = _build_dtype(self._header, self.floattype)

self.data = self.read_csv(
self.file, self.dtype, delimiter, deletechars, replace_space
)

@property
def obsnames(self):
Expand Down

0 comments on commit d1dbe76

Please sign in to comment.