diff --git a/autotest/t004_test_utilarray.py b/autotest/t004_test_utilarray.py index cc413fa546..ad47b701d5 100644 --- a/autotest/t004_test_utilarray.py +++ b/autotest/t004_test_utilarray.py @@ -889,9 +889,30 @@ def test_util3d_reset(): ml.bas6.strt = arr +def test_mflist_fromfile(): + """test that when a file is passed to stress period data, + the .array attribute will load the file + """ + import pandas as pd + import flopy + + wel_data = pd.DataFrame([(0,1,2, -50.0),(0,5,5, -50.0)], + columns=['k', 'i', 'j', 'flux']) + wel_data.to_csv('wel_000.dat', index=False, sep=' ',header=False) + + nwt_model = flopy.modflow.Modflow('nwt_testmodel',verbose=True) + dis = flopy.modflow.ModflowDis(nwt_model, nlay=1, nrow=10, ncol=10, delr=500.0, + delc=500.0, top=100.0, botm=50.0) + wel = flopy.modflow.ModflowWel(nwt_model, stress_period_data={0: 'wel_000.dat'}) + flx_array = wel.stress_period_data.array["flux"][0] + for k,i,j,flx in zip(wel_data.k,wel_data.i,wel_data.j,wel_data.flux): + assert flx_array[k,i,j] == flx + + if __name__ == "__main__": # test_util3d_reset() - test_mflist() + #test_mflist() + test_mflist_fromfile() # test_new_get_file_entry() # test_arrayformat() # test_util2d_external_free_nomodelws() diff --git a/flopy/utils/util_list.py b/flopy/utils/util_list.py index 4470ceba95..3aaee15df8 100644 --- a/flopy/utils/util_list.py +++ b/flopy/utils/util_list.py @@ -1086,6 +1086,8 @@ def to_array(self, kper=0, mask=False): kper = self.__find_last_kper(kper) sarr = self.data[kper] + if isinstance(sarr, str): + sarr = self.__fromfile(sarr) if np.isscalar(sarr): # if there are no entries for this kper