-
Notifications
You must be signed in to change notification settings - Fork 23
PEP8 improvements #113
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
PEP8 improvements #113
Conversation
demiangomez#111 Have some suggestions todo pep8
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.
Thank you @MarkusHackspacher for the pull request, we appreciate it =) I added a few more changes to this as a PR on your fork and branch.
There are a few additions I left as comments in the review instead of as commits, so that we'd don't have any merge conflicts when this gets approved and merged.
com/AlterETM.py
Outdated
@@ -87,8 +87,8 @@ def print_params(cnn, stnlist): | |||
% (station['NetworkCode'], station['StationCode']), as_dict=True) | |||
|
|||
for p in params: | |||
print(' %s.%s %-5s %-5s %2i' \ | |||
% (station['NetworkCode'], station['StationCode'], p['soln'], p['object'], p['terms'])) | |||
print(' %s.%s %-5s %-5s %2i' % (station['NetworkCode'], station['StationCode'], |
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.
how about:
print(' %s.%s %-5s %-5s %2i' % (station['NetworkCode'],
station['StationCode'],
p['soln'], p['object'],
p['terms']))
so we stay under the 79 character length?
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.
Is 80 length today useful? Modern editor could more.
In PR #109 in .github/workflows/python-package-conda.yml line 29+30 is set to --max-line-length=127
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
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.
Yes, most projects still use a 79 character limit-- the character length convention is partly so that multiple editor windows can be opened side by side for comparing files.
Right now, #109 is just running flake8 as warnings, but there will be another github runner automation run for new Pull Requests that won't pass with pep8 errors, and will likely use the 79 character limit.
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.
Thank you, have a question about the Output Formatting, what code style you preferred?
- Old-style String Formatting (% operator): This method is less preferred in newer Python code but still works.
- String Formatting (.format() method)
- Formatted String Literals (f-strings) (Python 3.6+)
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.
My strong preference and vote is for us to use Formatted String Literals (f-strings) moving forward.
We are currently pinned to using sklearn 1.1 or newer (which requires Python 3.8+)... and even if we were to remove that dependency, we are still required to use numpy version 1.19.5 or newer (which requires Python 3.6+). So we should always be on Python 3.6+ and have f-strings available as part of the standard library.
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.
That sounds this line would change in the future.
If it possible say ok to this review and accept the PR? The other lines you requested, I make no change in that line, only a line upper.
@@ -244,11 +231,8 @@ def apply_change(cnn, station, tpar, soln): | |||
# check if solution exists for this station | |||
try: | |||
epar = cnn.get('etm_params', ppar, list(ppar.keys())) | |||
|
|||
print(' >> Found a set of matching parameters for station ' + station_soln) |
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.
break this line into two? Python let's you do in parenthesis implicitly like this:
print(' >> Found a set of matching parameters for station '
+ station_soln)
@@ -161,7 +150,7 @@ def insert_modify_param(parser, cnn, stnlist, args): | |||
parser.error('jump type == 1 but no relaxation parameter, please specify relaxation') | |||
|
|||
elif ftype == 'q': | |||
tpar.object = 'periodic' | |||
tpar.object = 'periodic' | |||
tpar.frequencies = [float(1/float(p)) for p in args.function_type[1:]] |
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.
Break this line into 2? Python let's you do implicit line continuation over brackets like this:
tpar.frequencies = [float(1/float(p)) for p in
args.function_type[1:]]
@demiangomez do we need these imports on lines 14-17?
|
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.
@MarkusHackspacher sure, this looks good to merge. We'll revisit the string parsing and formatting in different PRs
#111
Have some suggestions todo pep8