Skip to content

Commit 2f67cf6

Browse files
committed
Upgrade to fstrings
1 parent 3c3b036 commit 2f67cf6

File tree

13 files changed

+20
-23
lines changed

13 files changed

+20
-23
lines changed

docs/examples/example_dask_chunk_OCMs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_pop(mode, chunk_mode):
247247
filenames = str(data_folder / "t.x1_SAMOC_flux.1690*.nc")
248248
variables = {"U": "UVEL", "V": "VVEL", "W": "WVEL"}
249249
timestamps = np.expand_dims(
250-
np.array([np.datetime64("2000-%.2d-01" % m) for m in range(1, 7)]), axis=1
250+
np.array([np.datetime64(f"2000-{m:02d}-01") for m in range(1, 7)]), axis=1
251251
)
252252
dimensions = {"lon": "ULON", "lat": "ULAT", "depth": "w_dep"}
253253
chs = False

docs/examples/example_moving_eddies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def moving_eddies_example(
146146

147147
# Execute for 1 week, with 1 hour timesteps and hourly output
148148
runtime = timedelta(days=7)
149-
print("MovingEddies: Advecting %d particles for %s" % (npart, str(runtime)))
149+
print(f"MovingEddies: Advecting {npart} particles for {runtime}")
150150
pset.execute(
151151
method,
152152
runtime=runtime,
@@ -177,7 +177,7 @@ def test_moving_eddies_fwdbwd(mode, mesh, tmpdir, npart=2):
177177
runtime = timedelta(days=1)
178178
dt = timedelta(minutes=5)
179179
outputdt = timedelta(hours=1)
180-
print("MovingEddies: Advecting %d particles for %s" % (npart, str(runtime)))
180+
print(f"MovingEddies: Advecting {npart} particles for {runtime}")
181181
outfile = tmpdir.join("EddyParticlefwd")
182182
pset.execute(
183183
method,

docs/examples/example_peninsula.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def peninsula_example(
168168
out = (
169169
pset.ParticleFile(name=outfile, outputdt=timedelta(hours=1)) if output else None
170170
)
171-
print("Peninsula: Advecting %d particles for %s" % (npart, str(time)))
171+
print(f"Peninsula: Advecting {npart} particles for {time}")
172172
pset.execute(k_adv + k_p, runtime=time, dt=dt, output_file=out)
173173

174174
if verbose:

docs/examples/example_stommel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def stommel_example(
160160

161161
maxage = runtime.total_seconds() if maxage is None else maxage
162162
fieldset.add_constant("maxage", maxage)
163-
print("Stommel: Advecting %d particles for %s" % (npart, runtime))
163+
print(f"Stommel: Advecting {npart} particles for {runtime}")
164164
parcels.timer.psetinit.stop()
165165
parcels.timer.psetrun = parcels.timer.Timer("Pset_run", parent=parcels.timer.pset)
166166
pset.execute(

parcels/compilation/codegenerator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def __init__(self, fieldset=None, ptype=JITParticle):
226226

227227
def get_tmp(self):
228228
"""Create a new temporary variable name."""
229-
tmp = "parcels_tmpvar%d" % self._tmp_counter
229+
tmp = f"parcels_tmpvar{self._tmp_counter:d}"
230230
self._tmp_counter += 1
231231
self.tmp_vars += [tmp]
232232
return tmp

parcels/field.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ def _search_indices_curvilinear(self, x, y, z, ti=-1, time=-1, particle=None, se
12421242
(xi, yi) = self._reconnect_bnd_indices(xi, yi, grid.xdim, grid.ydim, grid.mesh)
12431243
it += 1
12441244
if it > maxIterSearch:
1245-
print("Correct cell not found after %d iterations" % maxIterSearch)
1245+
print(f"Correct cell not found after {maxIterSearch} iterations")
12461246
raise FieldOutOfBoundError(x, y, 0, field=self)
12471247
xsi = max(0.0, xsi)
12481248
eta = max(0.0, eta)
@@ -2532,13 +2532,13 @@ def __init__(self, name: str, F, V=None, W=None):
25322532
assert isinstance(Fi, Field) and isinstance(
25332533
Vi, Field
25342534
), "F, and V components of a NestedField must be Field"
2535-
self.append(VectorField(name + "_%d" % i, Fi, Vi))
2535+
self.append(VectorField(f"{name}_{i}", Fi, Vi))
25362536
else:
25372537
for i, Fi, Vi, Wi in zip(range(len(F)), F, V, W, strict=True):
25382538
assert (
25392539
isinstance(Fi, Field) and isinstance(Vi, Field) and isinstance(Wi, Field)
25402540
), "F, V and W components of a NestedField must be Field"
2541-
self.append(VectorField(name + "_%d" % i, Fi, Vi, Wi))
2541+
self.append(VectorField(f"{name}_{i}", Fi, Vi, Wi))
25422542
self.name = name
25432543

25442544
def __getitem__(self, key):

parcels/kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def get_kernel_compile_files(self):
418418
dyn_dir = mpi_comm.bcast(dyn_dir, root=0)
419419
basename = cache_name if mpi_rank == 0 else None
420420
basename = mpi_comm.bcast(basename, root=0)
421-
basename = basename + "_%d" % mpi_rank
421+
basename = f"{basename}_{mpi_rank}"
422422
else:
423423
cache_name = (
424424
self._cache_key

parcels/particle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def __del__(self):
201201

202202
def __repr__(self):
203203
time_string = "not_yet_set" if self.time is None or np.isnan(self.time) else f"{self.time:f}"
204-
p_string = "P[%d](lon=%f, lat=%f, depth=%f, " % (self.id, self.lon, self.lat, self.depth)
204+
p_string = f"P[{self.id}](lon={self.lon:f}, lat={self.lat:f}, depth={self.depth:f}, "
205205
for var in vars(type(self)):
206206
if var in ["lon_nextloop", "lat_nextloop", "depth_nextloop", "time_nextloop"]:
207207
continue

parcels/particledata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def getPType(self):
460460

461461
def __repr__(self):
462462
time_string = "not_yet_set" if self.time is None or np.isnan(self.time) else f"{self.time:f}"
463-
p_string = "P[%d](lon=%f, lat=%f, depth=%f, " % (self.id, self.lon, self.lat, self.depth)
463+
p_string = f"P[{self.id}](lon={self.lon:f}, lat={self.lat:f}, depth={self.depth:f}, "
464464
for var in self._pcoll.ptype.variables:
465465
if var.name in [
466466
"lon_nextloop",

parcels/particleset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ def execute(
11931193
raise RuntimeError(
11941194
"Field writing during execution only works for Fields with one snapshot in time"
11951195
)
1196-
fldfilename = str(output_file.fname).replace(".zarr", "_%.4d" % fld.to_write)
1196+
fldfilename = str(output_file.fname).replace(".zarr", f"_{fld.to_write:04d}")
11971197
fld.write(fldfilename)
11981198
fld.to_write += 1
11991199

0 commit comments

Comments
 (0)