Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1df40e

Browse files
Issue #1498 mf6 Package: copy method is broken (#1505)
Fixes #1498 # Description Fix broken copy method # Checklist <!--- Before requesting review, please go through this checklist: --> - [x] Links to correct issue - [x] 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 --------- Co-authored-by: JoerivanEngelen <[email protected]>
1 parent b63b0b6 commit e1df40e

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

docs/api/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Fixed
2626
:meth:`imod.mf6.GeneralHeadBoundary.clip_box` threw an error when
2727
``time_start`` or ``time_end`` were set to ``None`` and a ``"repeat_stress"``
2828
was included in the dataset.
29+
- Fixed bug where :meth:`imod.mf6.package.copy` threw an error.
2930
- Sorting issue in :func:`imod.prepare.assign_wells`. This could cause
3031
:class:`imod.mf6.Well` to assign wells to the wrong cells.
3132
- Fixed crash upon calling :meth:`imod.mf6.Well.clip_box` when the top/bottom

imod/mf6/package.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ def _validate_init_schemata(self, validate: bool):
372372

373373
def copy(self) -> Any:
374374
# All state should be contained in the dataset.
375-
return type(self)(**self.dataset.copy().to_dict())
375+
dataset_copy = cast(Mapping[str, Any], self.dataset.copy())
376+
return type(self)(**dataset_copy)
376377

377378
def clip_box(
378379
self,

imod/tests/test_mf6/test_mf6_chd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def test_render(head):
7373
assert actual == expected
7474

7575

76+
def test_copy(head):
77+
chd = imod.mf6.ConstantHead(
78+
head, print_input=True, print_flows=True, save_flows=True
79+
)
80+
chd2 = chd.copy()
81+
assert isinstance(chd2, ConstantHead)
82+
assert chd2.dataset.equals(chd.dataset)
83+
84+
7685
def test_from_file(head, tmp_path):
7786
directory = pathlib.Path("mymodel")
7887
globaltimes = np.array(["2000-01-01"], dtype="datetime64[ns]")

imod/tests/test_mf6/test_mf6_dis.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ def test_render(idomain_and_bottom):
7676
assert actual == expected
7777

7878

79+
def test_copy(idomain_and_bottom):
80+
idomain, bottom = idomain_and_bottom
81+
82+
dis = imod.mf6.StructuredDiscretization(top=200.0, bottom=bottom, idomain=idomain)
83+
dis2 = dis.copy()
84+
assert isinstance(dis2, imod.mf6.StructuredDiscretization)
85+
assert dis2.dataset.equals(dis.dataset)
86+
87+
7988
def test_wrong_dtype(idomain_and_bottom):
8089
idomain, bottom = idomain_and_bottom
8190

imod/tests/test_mf6/test_mf6_disv.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def test_wrong_dtype(idomain_and_bottom):
7979
)
8080

8181

82+
def test_copy(idomain_and_bottom):
83+
idomain, bottom = idomain_and_bottom
84+
disv = imod.mf6.VerticesDiscretization(top=200.0, bottom=bottom, idomain=idomain)
85+
disv2 = disv.copy()
86+
assert isinstance(disv2, imod.mf6.VerticesDiscretization)
87+
assert disv2.dataset.equals(disv.dataset)
88+
89+
8290
def test_zero_thickness_validation(idomain_and_bottom):
8391
idomain, bottom = idomain_and_bottom
8492
# Create a bottom array that has constant value of -1 across all layers, so

0 commit comments

Comments
 (0)