-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STY: manual fixes for newly flagged violations of UP031 #5064
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,7 +253,7 @@ def save_as_dataset(self, filename=None, fields=None): | |
""" | ||
|
||
ds = self.data.ds | ||
keyword = "%s_clump_%d" % (str(ds), self.clump_id) | ||
keyword = f"{ds}_clump_{self.clump_id}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, isn't |
||
filename = get_output_filename(filename, keyword, ".h5") | ||
|
||
# collect clump info fields | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,7 +335,7 @@ def trajectory_from_index(self, index): | |
""" | ||
mask = np.isin(self.indices, (index,), assume_unique=True) | ||
if not np.any(mask): | ||
print("The particle index %d is not in the list!" % (index)) | ||
print(f"The particle index {index} is not in the list!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i know you're going for a 1:1 refactor here... but what about moving this string to the actual There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, but I'd prefer to do it in a follow up PR. I'm worried about making a breaking change for anyone and unintentionally hiding it behind a giant refactor. |
||
raise IndexError | ||
fields = sorted(self.field_data.keys()) | ||
traj = {} | ||
|
@@ -375,7 +375,7 @@ def write_out(self, filename_base): | |
[self.times[it]] + [self[field][ix, it] for field in fields] | ||
) | ||
) | ||
fid = open(filename_base + "_%d.dat" % self.indices[ix], "w") | ||
fid = open(f"{filename_base}_{self.indices[ix]}.dat", "w") | ||
fid.writelines(outlines) | ||
fid.close() | ||
del fid | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,9 +196,7 @@ def _generate_particle_fields(self, extra_field_names): | |
self.known_int_fields = self.known_int_fields[0 : self.num_int_base] | ||
|
||
# these are extra integer fields | ||
extra_int_fields = [ | ||
"particle_int_comp%d" % i for i in range(self.num_int_extra) | ||
] | ||
extra_int_fields = [f"particle_int_comp{i}" for i in range(self.num_int_extra)] | ||
self.known_int_fields.extend( | ||
[(self.particle_type, field) for field in extra_int_fields] | ||
) | ||
|
@@ -216,7 +214,7 @@ def _generate_particle_fields(self, extra_field_names): | |
assert len(extra_field_names) == self.num_real_extra | ||
else: | ||
extra_field_names = [ | ||
"particle_real_comp%d" % i for i in range(self.num_real_extra) | ||
f"particle_real_comp{i}" for i in range(self.num_real_extra) | ||
] | ||
|
||
self.known_real_fields.extend( | ||
|
@@ -1478,7 +1476,7 @@ def __init__(self, header_fn): | |
if len(line) == 1: | ||
line = f.readline() | ||
continue | ||
self.data["species_%d" % i] = [float(val) for val in line] | ||
self.data[f"species_{i}"] = [float(val) for val in line] | ||
i = i + 1 | ||
line = f.readline() | ||
|
||
|
@@ -1497,8 +1495,8 @@ def __init__(self, ds, dataset_type="boxlib_native"): | |
for key, val in self.warpx_header.data.items(): | ||
if key.startswith("species_"): | ||
i = int(key.split("_")[-1]) | ||
charge_name = "particle%.1d_charge" % i | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a weird one. As far as I understand |
||
mass_name = "particle%.1d_mass" % i | ||
charge_name = f"particle{i}_charge" | ||
mass_name = f"particle{i}_mass" | ||
self.parameters[charge_name] = val[0] | ||
self.parameters[mass_name] = val[1] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,7 +320,7 @@ def _parse_parameter_file(self): | |
self.parameters["wspecies"] = wspecies[:n] | ||
self.parameters["lspecies"] = lspecies[:n] | ||
for specie in range(n): | ||
self.particle_types.append("specie%i" % specie) | ||
self.particle_types.append(f"specie{specie}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe in English, 'species' is actually invariable, but I'm keeping bug-for-bug compatibility in this pure refactor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the etymology rabbit hole for "specie" is kinda fun. I could be convinced that it's more appropriate to use specie for particle types in a numerical simulation: maybe having a variety of particle types is more similar to minting different types of coins than it is to variations in taxonomical classification. But most likely species was meant here :) |
||
self.particle_types_raw = tuple(self.particle_types) | ||
ls_nonzero = np.diff(lspecies)[: n - 1] | ||
ls_nonzero = np.append(lspecies[0], ls_nonzero) | ||
|
@@ -611,7 +611,7 @@ def _parse_parameter_file(self): | |
else: | ||
particle_header_vals[a1] = arr[:a2] | ||
for specie in range(n): | ||
self.particle_types.append("specie%i" % specie) | ||
self.particle_types.append(f"specie{specie}") | ||
self.particle_types_raw = tuple(self.particle_types) | ||
ls_nonzero = np.diff(lspecies)[: n - 1] | ||
ls_nonzero = np.append(lspecies[0], ls_nonzero) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be explicitly specified as follows?
Or
nv/3
may indeed be a float rather than an int.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch. I think your second suggestion is more in line with the original. Thanks !