-
Notifications
You must be signed in to change notification settings - Fork 2
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
Sourcery refactored main branch #1
Conversation
hi = {} | ||
for icode in indice_codes: | ||
hi[icode] = getattr(indice_class, icode)() | ||
return hi | ||
return {icode: getattr(indice_class, icode)() for icode in indice_codes} |
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.
Function indices
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
# Dry points, namely strict baseflow. | ||
dry = ~(wet1 + wet2 + wet3 + wet4) | ||
|
||
return dry | ||
return ~(wet1 + wet2 + wet3 + wet4) |
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.
Function strict_baseflow
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# Dry points, namely strict baseflow.
# calculate the Kling-Gupta Efficiency KGE | ||
kge_ = 1 - np.sqrt((r - 1) ** 2 + (alpha - 1) ** 2 + (beta - 1) ** 2) | ||
|
||
return kge_ | ||
return 1 - np.sqrt((r - 1) ** 2 + (alpha - 1) ** 2 + (beta - 1) ** 2) |
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.
Function KGE
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# calculate the Kling-Gupta Efficiency KGE
annual_BFI = annual_b / annual_Q | ||
else: | ||
idx_year = date.Y - date.Y.min() | ||
counts = np.bincount(idx_year) | ||
idx_valid = counts > 0 | ||
annual_b = np.bincount(idx_year, weights=b)[idx_valid] / counts[idx_valid] | ||
annual_Q = np.bincount(idx_year, weights=Q)[idx_valid] / counts[idx_valid] | ||
annual_BFI = annual_b / annual_Q | ||
|
||
annual_BFI = annual_b / annual_Q |
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.
Function maxmium_BFI
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
year_delete = [] | ||
for y in year_unique: | ||
if (Q[year == y] >= 0).sum() < 120: | ||
year_delete.append(y) | ||
return year_delete | ||
return [y for y in year_unique if (Q[year == y] >= 0).sum() < 120] |
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.
Function clean_streamflow_jit
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into list comprehension (
list-comprehension
)
allnp[group_name] = allnp[group_name] + 1 | ||
allnp[group_name] += 1 | ||
if flag == 1: | ||
nnp[group_name] = nnp[group_name] + 1 | ||
nnp[group_name] += 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.
Function Indices._lf
refactored with the following changes:
- Replace assignment with augmented assignment [×2] (
aug-assign
)
if self.use_median is True: | ||
return stat.median() | ||
return stat.mean() | ||
return stat.median() if self.use_median is True else stat.mean() |
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.
Function Indices.DL18
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
stat = self.data_monthly_mean[self.data_monthly_mean == 0].count() | ||
return stat | ||
return self.data_monthly_mean[self.data_monthly_mean == 0].count() |
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.
Function Indices.DL20
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if self.use_median: | ||
stat = stat.median() | ||
else: | ||
stat = stat.mean() | ||
stat = stat.median() if self.use_median else stat.mean() |
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.
Function Indices.DH1
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
table = [] | ||
table.append(lq[lq < 0.1 * lma1]) | ||
table.append(lq[(lq >= 0.1 * lma1) & (lq < 0.25 * lma1)]) | ||
table.append(lq[(lq >= 0.25 * lma1) & (lq < 0.5 * lma1)]) | ||
table.append(lq[(lq >= 0.5 * lma1) & (lq < 0.75 * lma1)]) | ||
table.append(lq[(lq >= 0.75 * lma1) & (lq < lma1)]) | ||
table.append(lq[(lq >= lma1) & (lq < 1.25 * lma1)]) | ||
table.append(lq[(lq >= 1.25 * lma1) & (lq < 1.5 * lma1)]) | ||
table.append(lq[(lq >= 1.5 * lma1) & (lq < 1.75 * lma1)]) | ||
table.append(lq[(lq >= 1.75 * lma1) & (lq < 2.0 * lma1)]) | ||
table.append(lq[(lq >= 2.0 * lma1) & (lq < 2.25 * lma1)]) | ||
table.append(lq[(lq >= 2.25 * lma1)]) | ||
table = [ | ||
lq[lq < 0.1 * lma1], | ||
lq[(lq >= 0.1 * lma1) & (lq < 0.25 * lma1)], | ||
lq[(lq >= 0.25 * lma1) & (lq < 0.5 * lma1)], | ||
lq[(lq >= 0.5 * lma1) & (lq < 0.75 * lma1)], | ||
lq[(lq >= 0.75 * lma1) & (lq < lma1)], | ||
lq[(lq >= lma1) & (lq < 1.25 * lma1)], | ||
lq[(lq >= 1.25 * lma1) & (lq < 1.5 * lma1)], | ||
lq[(lq >= 1.5 * lma1) & (lq < 1.75 * lma1)], | ||
lq[(lq >= 1.75 * lma1) & (lq < 2.0 * lma1)], | ||
lq[(lq >= 2.0 * lma1) & (lq < 2.25 * lma1)], | ||
lq[lq >= 2.25 * lma1], | ||
] |
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.
Function Indices._pre_ta1_ta2
refactored with the following changes:
- Merge append into list declaration [×11] (
merge-list-append
) - Convert for loop into list comprehension (
list-comprehension
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.88%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!