Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(util_list.py): change get_dataframe() to iterate thru data.keys() instead of range(nper) #612

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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