Skip to content

Commit 0287d7c

Browse files
Throwing error when add_constant is not called with float or int
1 parent c58d7f3 commit 0287d7c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

parcels/fieldset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ def add_constant(self, name, value):
164164
"""
165165
if name in self.constants:
166166
raise ValueError(f"FieldSet already has a constant with name '{name}'")
167-
if isinstance(value, np.timedelta64):
168-
value = value / np.timedelta64(1, "s") # Convert to seconds
167+
if not isinstance(value, (float, np.float32, int, np.int32)):
168+
raise ValueError(f"FieldSet constants have to be of type float or int, got a {type(value)}")
169169
self.constants[name] = np.float32(value)
170170

171171
@property

tests/v4/test_diffusion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_fieldKh_SpatiallyVaryingDiffusion(mesh_type, kernel):
7575
Kh_meridional = Field("Kh_meridional", ds["Kh_meridional"], grid=grid, mesh_type=mesh_type, interp_method=XBiLinear)
7676
UV = VectorField("UV", U, V)
7777
fieldset = FieldSet([U, V, UV, Kh_zonal, Kh_meridional])
78-
fieldset.add_constant("dres", ds["lon"][1] - ds["lon"][0])
78+
fieldset.add_constant("dres", float(ds["lon"][1] - ds["lon"][0]))
7979

8080
npart = 100
8181

0 commit comments

Comments
 (0)