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

Sourcery refactored main branch #1

Merged
merged 1 commit into from
Jun 29, 2022
Merged

Sourcery refactored main branch #1

merged 1 commit into from
Jun 29, 2022

Conversation

sourcery-ai[bot]
Copy link
Contributor

@sourcery-ai sourcery-ai bot commented Jun 27, 2022

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:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from timcera June 27, 2022 03:00
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}
Copy link
Contributor Author

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:

# Dry points, namely strict baseflow.
dry = ~(wet1 + wet2 + wet3 + wet4)

return dry
return ~(wet1 + wet2 + wet3 + wet4)
Copy link
Contributor Author

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:

This removes the following comments ( why? ):

# Dry points, namely strict baseflow.

Comment on lines -76 to +73
# 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)
Copy link
Contributor Author

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:

This removes the following comments ( why? ):

# calculate the Kling-Gupta Efficiency KGE

Comment on lines -76 to +82
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
Copy link
Contributor Author

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:

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]
Copy link
Contributor Author

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:

Comment on lines -387 to +388
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
Copy link
Contributor Author

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)

Comment on lines -574 to +573
if self.use_median is True:
return stat.median()
return stat.mean()
return stat.median() if self.use_median is True else stat.mean()
Copy link
Contributor Author

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:

Comment on lines -586 to +583
stat = self.data_monthly_mean[self.data_monthly_mean == 0].count()
return stat
return self.data_monthly_mean[self.data_monthly_mean == 0].count()
Copy link
Contributor Author

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:

Comment on lines -591 to +587
if self.use_median:
stat = stat.median()
else:
stat = stat.mean()
stat = stat.median() if self.use_median else stat.mean()
Copy link
Contributor Author

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:

Comment on lines -704 to +709
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],
]
Copy link
Contributor Author

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:

@sourcery-ai
Copy link
Contributor Author

sourcery-ai bot commented Jun 27, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.88%.

Quality metrics Before After Change
Complexity 2.32 ⭐ 2.02 ⭐ -0.30 👍
Method Length 50.66 ⭐ 50.15 ⭐ -0.51 👍
Working memory 7.37 🙂 7.25 🙂 -0.12 👍
Quality 74.13% 🙂 75.01% 0.88% 👍
Other metrics Before After Change
Lines 2702 2653 -49
Changed files Quality Before Quality After Quality Change
src/hydrotoolbox/hydrotoolbox.py 54.09% 🙂 55.42% 🙂 1.33% 👍
src/hydrotoolbox/baseflow/comparison.py 56.19% 🙂 56.27% 🙂 0.08% 👍
src/hydrotoolbox/baseflow/param_estimate.py 62.92% 🙂 63.53% 🙂 0.61% 👍
src/hydrotoolbox/baseflow/utils.py 70.55% 🙂 70.03% 🙂 -0.52% 👎
src/hydrotoolbox/baseflow/methods/CM.py 64.21% 🙂 65.43% 🙂 1.22% 👍
src/hydrotoolbox/baseflow/methods/EWMA.py 65.29% 🙂 66.51% 🙂 1.22% 👍
src/hydrotoolbox/baseflow/methods/Eckhardt.py 71.90% 🙂 73.97% 🙂 2.07% 👍
src/hydrotoolbox/baseflow/methods/Furey.py 72.42% 🙂 74.47% 🙂 2.05% 👍
src/hydrotoolbox/baseflow/methods/LH.py 49.21% 😞 50.24% 🙂 1.03% 👍
src/hydrotoolbox/baseflow/methods/Local.py 78.47% ⭐ 78.94% ⭐ 0.47% 👍
src/hydrotoolbox/baseflow/methods/UKIH.py 67.47% 🙂 68.54% 🙂 1.07% 👍
src/hydrotoolbox/baseflow/methods/Willems.py 70.24% 🙂 72.24% 🙂 2.00% 👍
src/hydrotoolbox/indices/indices.py 79.33% ⭐ 80.06% ⭐ 0.73% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
src/hydrotoolbox/hydrotoolbox.py indices 5 ⭐ 619 ⛔ 23 ⛔ 31.13% 😞 Try splitting into smaller methods. Extract out complex expressions
src/hydrotoolbox/baseflow/param_estimate.py recession_coefficient 6 ⭐ 221 ⛔ 12 😞 47.38% 😞 Try splitting into smaller methods. Extract out complex expressions
src/hydrotoolbox/indices/indices.py Indices._pre_ta1_ta2 3 ⭐ 320 ⛔ 11 😞 47.72% 😞 Try splitting into smaller methods. Extract out complex expressions
src/hydrotoolbox/baseflow/methods/LH.py LH 13 🙂 174 😞 9 🙂 50.24% 🙂 Try splitting into smaller methods
src/hydrotoolbox/indices/indices.py Indices._lf 13 🙂 133 😞 11 😞 50.54% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

@timcera timcera merged commit cd16047 into main Jun 29, 2022
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

1 participant