From 5105f84f4d28d6135388d3a914e53373bb4e2ed0 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Fri, 26 Dec 2025 08:18:30 -0500 Subject: [PATCH 1/2] chore: accommodate numpy immutable scalar memory sharing --- autotest/test_copy.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/autotest/test_copy.py b/autotest/test_copy.py index e466d5007f..2461238287 100644 --- a/autotest/test_copy.py +++ b/autotest/test_copy.py @@ -39,7 +39,9 @@ def model_is_copy(m1, m2): return False for k, v in m1.__dict__.items(): v2 = m2.__dict__[k] - if v2 is v and type(v) not in [bool, str, type(None), float, int]: + # Allow identity sharing for immutable types including NumPy scalars + is_immutable = type(v) in [bool, str, type(None), float, int] or isinstance(v, np.generic) + if v2 is v and not is_immutable: # some mf6 objects aren't copied with deepcopy if isinstance(v, MFSimulationData): continue @@ -78,7 +80,9 @@ def package_is_copy(pk1, pk2): """ for k, v in pk1.__dict__.items(): v2 = pk2.__dict__[k] - if v2 is v and type(v) not in [bool, str, type(None), float, int, tuple]: + # Allow identity sharing for immutable types including NumPy scalars + is_immutable = type(v) in [bool, str, type(None), float, int, tuple] or isinstance(v, np.generic) + if v2 is v and not is_immutable: # Deep copy doesn't work for ModflowUtltas if not inspect.isclass(v): return False From 07078c76d0cfe05cdff799f121f22e10370bde17 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Fri, 26 Dec 2025 08:25:01 -0500 Subject: [PATCH 2/2] ruff --- autotest/test_copy.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/autotest/test_copy.py b/autotest/test_copy.py index 2461238287..86bd44917d 100644 --- a/autotest/test_copy.py +++ b/autotest/test_copy.py @@ -40,7 +40,9 @@ def model_is_copy(m1, m2): for k, v in m1.__dict__.items(): v2 = m2.__dict__[k] # Allow identity sharing for immutable types including NumPy scalars - is_immutable = type(v) in [bool, str, type(None), float, int] or isinstance(v, np.generic) + is_immutable = type(v) in [bool, str, type(None), float, int] or isinstance( + v, np.generic + ) if v2 is v and not is_immutable: # some mf6 objects aren't copied with deepcopy if isinstance(v, MFSimulationData): @@ -81,7 +83,14 @@ def package_is_copy(pk1, pk2): for k, v in pk1.__dict__.items(): v2 = pk2.__dict__[k] # Allow identity sharing for immutable types including NumPy scalars - is_immutable = type(v) in [bool, str, type(None), float, int, tuple] or isinstance(v, np.generic) + is_immutable = type(v) in [ + bool, + str, + type(None), + float, + int, + tuple, + ] or isinstance(v, np.generic) if v2 is v and not is_immutable: # Deep copy doesn't work for ModflowUtltas if not inspect.isclass(v):