diff --git a/docs/api/changelog.rst b/docs/api/changelog.rst index 1cbe89a3c..7132f2add 100644 --- a/docs/api/changelog.rst +++ b/docs/api/changelog.rst @@ -28,6 +28,8 @@ Added Fixed ~~~~~ +- Fixed resampling of Arrow-backed iMOD5 well timeseries when simulation + timesteps precede the first well timestep. - Fixed bug in :class:`imod.mf6.GroundwaterFlowModel` and :class:`imod.formats.prf.IpfResult` where names of wels were duplicated by increasing the character limit to 40 and enumerating wel names. diff --git a/imod/tests/test_mf6/test_utilities/test_resampling.py b/imod/tests/test_mf6/test_utilities/test_resampling.py index 5465e5abf..6ffc08cf2 100644 --- a/imod/tests/test_mf6/test_utilities/test_resampling.py +++ b/imod/tests/test_mf6/test_utilities/test_resampling.py @@ -80,6 +80,27 @@ def test_timeseries_resampling_2(): ) +def test_timeseries_resampling_before_start_with_arrow_dtypes(): + """ + Regression test for assigning the first well location to multiple rows when + the location columns use Arrow-backed dtypes. + """ + timeseries = initialize_timeseries( + [datetime(1989, 4, 3)], + [100.0], + ).convert_dtypes(dtype_backend="pyarrow") + # Keep time as NumPy datetime64, as produced by the iMOD5 import workflow. + timeseries["time"] = timeseries["time"].astype("datetime64[ns]") + new_dates = pd.date_range(datetime(1989, 1, 1), datetime(1989, 4, 3)) + + new_timeseries = resample_timeseries(timeseries, new_dates) + + assert len(new_timeseries) == 93 + assert (new_timeseries.loc[:91, "rate"] == 0.0).all() + assert (new_timeseries.loc[:91, "id"] == "ID").all() + assert new_timeseries.loc[92, "rate"] == 100.0 + + def test_timeseries_resampling_3(): # In this test, we resample a timeseries for a coarser output discretization. # The output times are a subset of the input times. diff --git a/imod/util/expand_repetitions.py b/imod/util/expand_repetitions.py index 981b85073..9f93e8d94 100644 --- a/imod/util/expand_repetitions.py +++ b/imod/util/expand_repetitions.py @@ -117,9 +117,10 @@ def resample_timeseries( ) if time_before_start_input[0]: intermediate_df.loc[time_before_start_input, "rate"] = 0.0 - intermediate_df.loc[time_before_start_input, location_columns] = ( - well_rate.iloc[0][location_columns], - ) + for column in location_columns: + intermediate_df.loc[time_before_start_input, column] = well_rate[ + column + ].iloc[0] # compute time difference from perious to current row time_diff_col = intermediate_df["time"].diff()