Skip to content

Commit

Permalink
fix(util_list.py): get_dataframe() iterating thru nper instead of dat…
Browse files Browse the repository at this point in the history
…a.keys(); fails for pers where itmp < 0 (#612)
  • Loading branch information
aleaf authored and langevin-usgs committed Jul 11, 2019
1 parent 6943cbb commit e4f0222
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion autotest/t004_test_utilarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,18 @@ def test_mflist():
sp_data = {0: [[1, 1, 1, 1.0], [1, 1, 2, 2.0], [1, 1, 3, 3.0]],
1: [1, 2, 4, 4.0]}
wel = flopy.modflow.ModflowWel(ml, stress_period_data=sp_data)
m4ds = ml.wel.stress_period_data.masked_4D_arrays
spd = wel.stress_period_data

# verify dataframe can be cast when spd.data.keys() != to ml.nper
# verify that dataframe is cast correctly by recreating spd.data items
df = wel.stress_period_data.get_dataframe()
for per, data in spd.data.items():
fluxcol = 'flux{}'.format(per)
dfper = df.dropna(subset=[fluxcol], axis=0).copy()
dfper.rename(columns={fluxcol: 'flux'}, inplace=True)
assert np.array_equal(dfper[['k', 'i', 'j', 'flux']].to_records(index=False), data)

m4ds = ml.wel.stress_period_data.masked_4D_arrays
sp_data = flopy.utils.MfList.masked4D_arrays_to_stress_period_data \
(flopy.modflow.ModflowWel.get_default_dtype(), m4ds)
assert np.array_equal(sp_data[0], ml.wel.stress_period_data[0])
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/util_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def get_dataframe(self, squeeze=True):
# create list of dataframes for each stress period
# each with index of k, i, j
dfs = []
for per in range(self._model.nper):
for per in self.data.keys():
recs = self.data[per]
if recs is None or recs is 0:
# add an empty dataframe if a stress period is
Expand Down

0 comments on commit e4f0222

Please sign in to comment.