Skip to content

Commit 2fdaeac

Browse files
Issue #1342 Also deepcopy HFB package upon calling clip_box (#1345)
Fixes #1342 # Description - Replace custom copy logic in ``clip_box`` with a call to ``deepcopy``, which works since #1327. - Also add missing unit test for ``clip_box`` # Checklist - [x] Links to correct issue - [ ] Update changelog, if changes affect users - [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737`` - [x] Unit tests were added - [ ] **If feature added**: Added/extended example
1 parent 85a8048 commit 2fdaeac

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

imod/mf6/hfb.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import abc
2-
import copy
32
import json
43
import textwrap
54
import typing
@@ -457,11 +456,9 @@ def __deepcopy__(self, memo):
457456
ds_vars.remove(var)
458457

459458
cls = type(self)
460-
new = cls._from_dataset(copy.deepcopy(self.dataset[ds_vars]))
459+
new = cls._from_dataset(deepcopy(self.dataset[ds_vars]))
461460
new.line_data = gpd.GeoDataFrame(
462-
copy.deepcopy(
463-
self.dataset[self._get_variable_names_for_gdf()].to_dataframe()
464-
),
461+
deepcopy(self.dataset[self._get_variable_names_for_gdf()].to_dataframe()),
465462
geometry="geometry",
466463
)
467464

@@ -800,10 +797,7 @@ def clip_box(
800797
-------
801798
sliced : Package
802799
"""
803-
cls = type(self)
804-
new = cls._from_dataset(copy.deepcopy(self.dataset))
805-
new.line_data = self.line_data
806-
return new
800+
return deepcopy(self)
807801

808802
def mask(self, _) -> Package:
809803
"""

imod/tests/test_mf6/test_mf6_hfb.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,33 @@ def test_custom_deepcopy():
911911
"layer": [1],
912912
},
913913
)
914-
hfb = HorizontalFlowBarrierResistance(geometry)
914+
hfb = SingleLayerHorizontalFlowBarrierResistance(geometry)
915915

916916
# Act
917917
hfb_copy = deepcopy(hfb)
918918

919919
# Assert
920920
assert hfb_copy.dataset.identical(hfb.dataset)
921+
922+
923+
def test_clip_box():
924+
# Arrange
925+
barrier_y = [11.0, 5.0, -1.0]
926+
barrier_x = [5.0, 5.0, 5.0]
927+
928+
geometry = gpd.GeoDataFrame(
929+
geometry=[linestrings(barrier_x, barrier_y)],
930+
data={
931+
"resistance": [1200.0],
932+
"layer": [1],
933+
},
934+
)
935+
hfb = SingleLayerHorizontalFlowBarrierResistance(geometry)
936+
937+
# Act
938+
hfb_clipped = hfb.clip_box(y_max=7.0)
939+
940+
# Assert
941+
# HFB currently not clipped but copied
942+
# FUTURE: Line data might be clipped in the future.
943+
assert hfb_clipped.dataset.identical(hfb.dataset)

0 commit comments

Comments
 (0)