-
Notifications
You must be signed in to change notification settings - Fork 34
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
STYLE: Fix filename and dirname creation floating point formatting #232
STYLE: Fix filename and dirname creation floating point formatting #232
Conversation
Fix formatting of numbers that can be floats when creating filenames and dirnames: when transitioning to f-strings (commit ac6040f), it was assumed that `sigma` and `nonrigid_grid_resolution` would be integers, based on the existing formatting. However, these attributes can be set to non-integer values. The pre-f-string transition solution, e.g.: ``` "iteration_%05d_sigma_%05d" % (self.total_iterations, self.sigma) ``` trimmed the decimal part, and thus, for e.g. `total_iterations` 20 and `sigma` 7.5, it would produce: ``` 'iteration_00020_sigma_00007' ``` With the introduction of f-strings, i.e. ``` f"iteration_{self.total_iterations:05d}_sigma_{self.sigma:05d}" ``` this would produce an error, since the `sigma` floating point value cannot be formatted as an integer: ``` {ValueError}ValueError("Unknown format code 'd' for object of type 'float'") ``` This patch set fixes the error by adopting the previous behavior: it trims the decimal part.
Thanks @jhlegarreta for looking at my question! |
I know it is not the best solution, but it is the behavior that it had before... You will agree with me that having a period in the filename/dirname is never a good solution. Happy to consider other solutions if you come up with any. |
@AlbertoImg I am merging this: the current workaround is better than a failure. As said, better strategies can be considered as new PRs. |
A workaround could be to use "f" instead of "d" in the formatting, and later on replacing the dot in the dirname string: |
@AlbertoImg Please, check the statement: the strings still have the integer specifier. I had already thought about the solution you proposed, but discarded it because the result would not be consistent with what you get when using only integers, e.g.:
You get |
Here "iteration_00010sigma_00075grid_00020", maybe confusing when comparing the format of the iterations and the others, but it is just my opinion. 'iteration_0010_sigma_0p75_grid_0p02' |
FYI: congeal_multisubject.py also has same issues. Thanks! Line 149 e.g. |
Can you be more specific? The fix for the issue reported in ac6040f#r143635819 for
|
The line number was wrong. I am sorry. The line were 479 and 491 |
OK. Watch the underscores and markdown highlighting. PR #236. |
Fix formatting of numbers that can be floats when creating filenames and dirnames: when transitioning to f-strings (commit ac6040f), it was assumed that
sigma
andnonrigid_grid_resolution
would be integers, based on the existing formatting. However, these attributes can be set to non-integer values. The pre-f-string transition solution, e.g.:trimmed the decimal part, and thus, for e.g.
total_iterations
20 andsigma
7.5, it would produce:With the introduction of f-strings, i.e.
this would produce an error, since the
sigma
floating point value cannot be formatted as an integer:This patch set fixes the error by adopting the previous behavior: it trims the decimal part.