Skip to content

Commit 89d8304

Browse files
authored
chore: accommodate numpy immutable scalar memory sharing (#2675)
With numpy 2.4.0, most scalars share memory numpy/numpy@5386540, relax some test comparisons to accommodate this
1 parent 7ef9f37 commit 89d8304

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

autotest/test_copy.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def model_is_copy(m1, m2):
3939
return False
4040
for k, v in m1.__dict__.items():
4141
v2 = m2.__dict__[k]
42-
if v2 is v and type(v) not in [bool, str, type(None), float, int]:
42+
# Allow identity sharing for immutable types including NumPy scalars
43+
is_immutable = type(v) in [bool, str, type(None), float, int] or isinstance(
44+
v, np.generic
45+
)
46+
if v2 is v and not is_immutable:
4347
# some mf6 objects aren't copied with deepcopy
4448
if isinstance(v, MFSimulationData):
4549
continue
@@ -78,7 +82,16 @@ def package_is_copy(pk1, pk2):
7882
"""
7983
for k, v in pk1.__dict__.items():
8084
v2 = pk2.__dict__[k]
81-
if v2 is v and type(v) not in [bool, str, type(None), float, int, tuple]:
85+
# Allow identity sharing for immutable types including NumPy scalars
86+
is_immutable = type(v) in [
87+
bool,
88+
str,
89+
type(None),
90+
float,
91+
int,
92+
tuple,
93+
] or isinstance(v, np.generic)
94+
if v2 is v and not is_immutable:
8295
# Deep copy doesn't work for ModflowUtltas
8396
if not inspect.isclass(v):
8497
return False

0 commit comments

Comments
 (0)