Skip to content
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

Replacing filters .format() calls with f-strings #5478

Merged
merged 5 commits into from
Jul 20, 2021

Conversation

alex-jw-brooks
Copy link
Contributor

Description

This PR replaces .format() calls on strings within the filters package with f-strings to partially address issue #5474.

Thank you!

Comment on lines +19 to +21
msg = (f'Window size for `threshold_sauvola` or '
f'`threshold_niblack` must not be even on any dimension. '
f'Got {axis_sizes}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first two lines here don't have to have the f since there is no substitution there, but I don't think it hurts. I don't know if it is more common to leave it off in that case as below? Maybe @mkcor has an opinion?

            msg = ('Window size for `threshold_sauvola` or '
                   '`threshold_niblack` must not be even on any dimension. '
                   f'Got {axis_sizes}')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grlee77 Yup, that should be fine as well. As far as I can tell, I don't think that there's too much out there in terms of style guidelines for this - I had left it this way after reading the PEP and a few posts like this one, as it felt more readable to me and less likely to lead to wrong messages if they were changed in the future.

I don't feel strongly about it though and am happy to change it if you'd prefer the lines without placeholders to be regular strings

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! At first I thought: Why bother with an extra, unnecessary f prefix? I like to follow a minimalist approach. But after reading the SO post @alex-jw-brooks linked to, I'm happy to go for the multi-line f prefix!

Comment on lines +19 to +21
msg = (f'Window size for `threshold_sauvola` or '
f'`threshold_niblack` must not be even on any dimension. '
f'Got {axis_sizes}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! At first I thought: Why bother with an extra, unnecessary f prefix? I like to follow a minimalist approach. But after reading the SO post @alex-jw-brooks linked to, I'm happy to go for the multi-line f prefix!

skimage/filters/rank/generic.py Outdated Show resolved Hide resolved
skimage/filters/rank/generic.py Outdated Show resolved Hide resolved
skimage/filters/thresholding.py Outdated Show resolved Hide resolved
skimage/filters/thresholding.py Outdated Show resolved Hide resolved
skimage/filters/thresholding.py Outdated Show resolved Hide resolved
skimage/filters/thresholding.py Outdated Show resolved Hide resolved
skimage/filters/thresholding.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@alex-jw-brooks alex-jw-brooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that first round of feedback - should ready for another pass whenever you both have a moment!

skimage/filters/rank/generic.py Outdated Show resolved Hide resolved
skimage/filters/thresholding.py Outdated Show resolved Hide resolved
@grlee77
Copy link
Contributor

grlee77 commented Jul 19, 2021

I am hoping to contribute to this project quite a bit - will make sure to try to work on standardizing on single quotes in other parts of the code as I interact with them in the future.

That is good to hear! If it is not too much hassle can you split it in two as suggested above (f-strings vs. other single quote changes)? We could merge the f-string part now and leave the other up for a day or two for potential comment.

@alex-jw-brooks
Copy link
Contributor Author

Sounds good, thanks @grlee77 and @mkcor - I went ahead and updated the PR to only include the original changes and the style changes on the f-strings from the review. I will plan to open a separate PR in the future for moving to single quotes on one of the packages to gather some feedback from the team to see if this is something in general most people would feel good about standardizing on for the rest of the library

Copy link
Member

@mkcor mkcor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @alex-jw-brooks!

stacklevel=2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this blank line removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintentional - added it back. Nice catch, and thank you for the quick reviews! 😄

skimage/filters/thresholding.py Outdated Show resolved Hide resolved
alex-jw-brooks and others added 2 commits July 20, 2021 10:37
Clarify multiotsu thresholding error message

Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org>
@grlee77 grlee77 merged commit 73d0040 into scikit-image:main Jul 20, 2021
@grlee77
Copy link
Contributor

grlee77 commented Jul 20, 2021

Thanks for your patience and responsiveness here @alex-jw-brooks. It is now merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants