Skip to content

Commit

Permalink
fix(csvfile): correction to read_csv args, close file handle (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Oct 16, 2022
1 parent 2eeefd4 commit a0a92ed
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
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
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 a0a92ed

Please sign in to comment.