Skip to content

Commit

Permalink
Resolve bugs related to F821 undefined name 'name' (#686)
Browse files Browse the repository at this point in the history
* fix(Mt3dPhc): missing filenames parameter; add basic test

* fix(backup_existing_dfns): fix variable name

* fix(mfstr): fix variable name and missing import

* fix(t022_test): catch ImportError and adjust expected data

* fix(mfde4): fixed-width load did not work

* fix(mflistfile): resolve undefined name 'e'

* fix(mfsms): load options
  • Loading branch information
mwtoews authored and langevin-usgs committed Oct 20, 2019
1 parent bbe3f55 commit da3ad6f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
18 changes: 18 additions & 0 deletions autotest/t013_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ def test_mt3d_create_woutmfmodel():
return


def test_mt3d_pht3d():
# Note: this test is incomplete!
model_ws = os.path.join('.', 'temp', 't013')

# Create MT3D model
mt = flopy.mt3d.Mt3dms(model_ws=model_ws)
phc = flopy.mt3d.Mt3dPhc(mt, minkin=[[[1]], [[2]]])

# Write the output
mt.write_input()

# confirm that MT3D files exist
assert os.path.isfile(
os.path.join(model_ws, '{}.{}'.format(mt.name, phc.extension[0])))

return


if __name__ == '__main__':
test_mt3d_create_withmfmodel()
test_mt3d_create_woutmfmodel()
Expand Down
11 changes: 5 additions & 6 deletions autotest/t022_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,18 @@ def test_swr_binary_obs(ipos=5):
for idx in range(ntimes):
df = sobj.get_dataframe(idx=idx, timeunit='S')
assert isinstance(df, pd.DataFrame), 'A DataFrame was not returned'
assert df.shape == (1, nobs+1), 'data shape is not (1, 9)'
assert df.shape == (1, nobs + 1), 'data shape is not (1, 10)'

for time in times:
df = sobj.get_dataframe(totim=time, timeunit='S')
assert isinstance(df, pd.DataFrame), 'A DataFrame was not returned'
assert df.shape == (1, 9), 'data shape is not (1, 9)'
assert df.shape == (1, nobs + 1), 'data shape is not (1, 10)'

df = h.get_dataframe(timeunit='D')
df = sobj.get_dataframe(timeunit='S')
assert isinstance(df, pd.DataFrame), 'A DataFrame was not returned'
assert df.shape == (101, 9), 'data shape is not (101, 9)'
except:
assert df.shape == (336, nobs + 1), 'data shape is not (336, 10)'
except ImportError:
print('pandas not available...')
pass

return

Expand Down
2 changes: 1 addition & 1 deletion flopy/mf6/utils/generate_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def backup_existing_dfns(flopy_dfn_path):
backup_folder = os.path.join(parent_folder, 'dfn_backup', timestr)
shutil.copytree(flopy_dfn_path, backup_folder)
assert os.path.isdir(backup_folder), \
'dfn backup files not found: {}'.format(pth)
'dfn backup files not found: {}'.format(backup_folder)
return


Expand Down
2 changes: 1 addition & 1 deletion flopy/modflow/mfde4.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def load(f, model, ext_unit_dict=None):
itmx = int(line[0:10].strip())
mxup = int(line[10:20].strip())
mxlow = int(line[20:30].strip())
mxbw = int(tline[30:40].strip())
mxbw = int(line[30:40].strip())
line = f.readline()
ifreq = int(line[0:10].strip())
mutd4 = int(line[10:20].strip())
Expand Down
5 changes: 3 additions & 2 deletions flopy/modflow/mfsms.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,10 @@ def load(f, model, ext_unit_dict=None):
# Record 1a
nopt = 0
opts = ['simple', 'moderate', 'complex']
options = []
for o in opts:
if o in line.lower():
options.append(0)
options.append(o)
nopt += 1

if nopt > 0:
Expand Down Expand Up @@ -546,7 +547,7 @@ def load(f, model, ext_unit_dict=None):
iacl=iacl, norder=norder, level=level, north=north,
iredsys=iredsys, rrctol=rrctol, idroptol=idroptol,
epsrn=epsrn, clin=clin, ipc=ipc, iscl=iscl,
iord=iord, rclosepcgu=rclosepcgu,
iord=iord, rclosepcgu=rclosepcgu, options=options,
relaxpcgu=relaxpcgu, unitnumber=unitnumber,
filenames=filenames)
return sms
Expand Down
11 changes: 6 additions & 5 deletions flopy/modflow/mfstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import numpy as np
from ..utils import MfList
from ..pakbase import Package
from .mfparbc import ModflowParBc as mfparbc
from ..utils.recarray_utils import create_empty_recarray


Expand Down Expand Up @@ -290,9 +291,9 @@ def __init__(self, model, mxacts=0, nss=0, ntrib=0, ndiv=0, icalc=0,
self.dtype = dtype[0]
self.dtype2 = dtype[1]
else:
auxnames = []
aux_names = []
if len(options) > 0:
auxnames = []
aux_names = []
it = 0
while True:
if 'aux' in options[it].lower():
Expand All @@ -301,9 +302,9 @@ def __init__(self, model, mxacts=0, nss=0, ntrib=0, ndiv=0, icalc=0,
it += 1
if it > len(options):
break
if len(auxnames) < 1:
auxnames = None
d, d2 = self.get_empty(1, 1, aux_names=auxnames,
if len(aux_names) < 1:
aux_names = None
d, d2 = self.get_empty(1, 1, aux_names=aux_names,
structured=self.parent.structured)
self.dtype = d.dtype
self.dtype2 = d2.dtype
Expand Down
2 changes: 1 addition & 1 deletion flopy/mt3d/mtphc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Mt3dPhc(Package):
def __init__(self, model, os=2, temp=25, asbin=0, eps_aqu=0, eps_ph=0,
scr_output=1, cb_offset=0, smse=['pH', 'pe'], mine=[], ie=[],
surf=[], mobkin=[], minkin=[], surfkin=[], imobkin=[],
extension='phc', unitnumber=None):
extension='phc', unitnumber=None, filenames=None):

if unitnumber is None:
unitnumber = Mt3dPhc.defaultunit()
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/mflistfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def _get_sp(self, ts, sp, seekpoint):
if len(re.findall('=', line)) == 2:
try:
entry, flux, cumu = self._parse_budget_line(line)
except e:
except Exception:
print('error parsing budget line in ts,sp', ts, sp)
return self.null_entries
if flux is None:
Expand Down

0 comments on commit da3ad6f

Please # to comment.