Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/api/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions imod/tests/test_mf6/test_utilities/test_resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions imod/util/expand_repetitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down