diff --git a/.docs/Notebooks/mf6_mnw2_tutorial01.py b/.docs/Notebooks/mf6_mnw2_tutorial01.py index 745afbb95d..6f09a523a6 100644 --- a/.docs/Notebooks/mf6_mnw2_tutorial01.py +++ b/.docs/Notebooks/mf6_mnw2_tutorial01.py @@ -77,11 +77,6 @@ ) node_data -# #### convert the DataFrame to a recarray for compatibility with flopy - -node_data = node_data.to_records() -node_data - # ### Stress period information # (could also be developed externally) @@ -97,7 +92,7 @@ stress_period_data pers = stress_period_data.groupby("per") -stress_period_data = {i: pers.get_group(i).to_records() for i in [0, 1]} +stress_period_data = {i: pers.get_group(i) for i in [0, 1]} stress_period_data # ### Make ``ModflowMnw2`` package object diff --git a/autotest/test_modflow.py b/autotest/test_modflow.py index 62675b9b27..253fa0fec3 100644 --- a/autotest/test_modflow.py +++ b/autotest/test_modflow.py @@ -915,11 +915,19 @@ def test_bcs_check(function_tmpdir): assert len(chk.summary_array) == 1 ghb = ModflowGhb(mf, stress_period_data={0: [0, 0, 0, 100, 1]}) + riv_spd = pd.DataFrame( + [[0, 0, 0, 0, 101.0, 10.0, 100.0], [0, 0, 0, 1, 80.0, 10.0, 90.0]], + columns=["per", "k", "i", "j", "stage", "cond", "rbot"], + ) + + pers = riv_spd.groupby("per") + riv_spd = {i: pers.get_group(i).drop("per", axis=1) for i in [0]} riv = ModflowRiv( mf, - stress_period_data={ - 0: [[0, 0, 0, 101, 10, 100], [0, 0, 1, 80, 10, 90]] - }, + stress_period_data=riv_spd, + # stress_period_data={ + # 0: [[0, 0, 0, 101, 10, 100], [0, 0, 1, 80, 10, 90]] + # }, ) chk = ghb.check() assert chk.summary_array["desc"][0] == "BC in inactive cell" diff --git a/flopy/modflow/mfmnw2.py b/flopy/modflow/mfmnw2.py index e3921d6cfb..f778591238 100644 --- a/flopy/modflow/mfmnw2.py +++ b/flopy/modflow/mfmnw2.py @@ -1075,6 +1075,12 @@ def __init__( dtype=self.get_default_spd_dtype(structured=self.structured), ) if stress_period_data is not None: + stress_period_data = { + per: sp.to_records(index=False) + if isinstance(sp, pd.DataFrame) + else sp + for per, sp in stress_period_data.items() + } for per, data in stress_period_data.items(): spd = ModflowMnw2.get_empty_stress_period_data( len(data), aux_names=aux diff --git a/flopy/modflow/mfriv.py b/flopy/modflow/mfriv.py index 7ab5800007..63e0ee155d 100644 --- a/flopy/modflow/mfriv.py +++ b/flopy/modflow/mfriv.py @@ -9,6 +9,7 @@ """ import numpy as np +import pandas as pd from ..pakbase import Package from ..utils import MfList @@ -194,9 +195,11 @@ def check(self, f=None, verbose=True, level=1, checktype=None): chk = self._get_check(f, verbose, level, checktype) chk.summary_array = basechk.summary_array - for per in self.stress_period_data.data.keys(): - if isinstance(self.stress_period_data.data[per], np.recarray): - spd = self.stress_period_data.data[per] + for per, data in self.stress_period_data.data.items(): + if isinstance(data, (np.recarray, pd.DataFrame)): + if isinstance(data, pd.DataFrame): + data = data.to_records(index=False).astype(self.dtype) + spd = data inds = ( (spd.k, spd.i, spd.j) if self.parent.structured diff --git a/flopy/utils/util_list.py b/flopy/utils/util_list.py index d1274cc0cb..62fdb5ef5e 100644 --- a/flopy/utils/util_list.py +++ b/flopy/utils/util_list.py @@ -417,7 +417,9 @@ def __cast_ndarray(self, kper, d): self.__vtype[kper] = np.recarray def __cast_dataframe(self, kper, d): - self.__cast_recarray(kper, d.to_records(index=False)) + self.__cast_recarray( + kper, d.to_records(index=False).astype(self.dtype) + ) def get_dataframe(self, squeeze=False): """