-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Conversation
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
| if self.line_before_msg: | ||
| _stdout.write("\n") | ||
| _stdout.write(self.preambule + " ... " + s) | ||
| _stdout.write(f"{self.preambule} ... {s}") |
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 PreambuleStream.write_msg refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| def getDescription(test): | ||
| doc_first_line = test.shortDescription() | ||
| if doc_first_line: | ||
| if doc_first_line := test.shortDescription(): |
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 QuietTestResult.getDescription refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| print("%s: %s" % (flavour,self.getDescription(test))) | ||
| print(f"{flavour}: {self.getDescription(test)}") | ||
| print(self.separator2) | ||
| print("%s" % err) | ||
| print(f"{err}") |
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 QuietTestResult.printErrorList refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| INSTALL_REQUIRES = sorted(set( | ||
| line.partition('#')[0].strip() | ||
| for file in (os.path.join(os.path.dirname(__file__), file) | ||
| for file in requirements) | ||
| for line in open(file) | ||
| ) - {''}) | ||
| INSTALL_REQUIRES = sorted( | ||
| ( | ||
| { | ||
| line.partition('#')[0].strip() | ||
| for file in ( | ||
| os.path.join(os.path.dirname(__file__), file) | ||
| for file in requirements | ||
| ) | ||
| for line in open(file) | ||
| } | ||
| - {''} | ||
| ) | ||
| ) |
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.
Lines 87-92 refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| FULLVERSION += '.dev0+' + GIT_REVISION[:7] | ||
| FULLVERSION += f'.dev0+{GIT_REVISION[:7]}' |
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 write_version_py refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| return super().__repr__() + ' # params=' + repr(self.params) | ||
| return f'{super().__repr__()} # params={repr(self.params)}' |
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 SklModel.__repr__ refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| ) | ||
| # first argument is 'self' | ||
| assert spec[0] == "self" | ||
| return {name: values[name] for name in spec[1:] if name in values} |
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 SklLearner._get_sklparams refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| def __call__(self, data, ret=Model.Value): | ||
| if isinstance(data, Table): | ||
| with data.force_unlocked(data.X): | ||
| return super().__call__(data, ret) | ||
| else: | ||
| if not isinstance(data, Table): | ||
| return super().__call__(data, ret) | ||
| with data.force_unlocked(data.X): | ||
| return super().__call__(data, ret) |
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 CatGBModel.__call__ refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| return super().__repr__() + ' # params=' + repr(self.params) | ||
| return f'{super().__repr__()} # params={repr(self.params)}' |
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 CatGBModel.__repr__ refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| vals = [attr.values[j] for j in sorted(child.condition)] | ||
| if not vals: | ||
| child.description = "(unreachable)" | ||
| if vals := [attr.values[j] for j in sorted(child.condition)]: | ||
| child.description = ( | ||
| vals[0] | ||
| if len(vals) == 1 | ||
| else f'{", ".join(vals[:-1])} or {vals[-1]}' | ||
| ) | ||
| else: | ||
| child.description = vals[0] if len(vals) == 1 else \ | ||
| "{} or {}".format(", ".join(vals[:-1]), vals[-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 MappedDiscreteNode._set_child_descriptions refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Swap if/else branches (
swap-if-else-branches) - Replace call to format with f-string (
use-fstring-for-formatting)
| child.description = \ | ||
| "{} {}".format("≤>"[child_idx], attr.str_val(threshold)) | ||
| child.description = f'{"≤>"[child_idx]} {attr.str_val(threshold)}' |
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 NumericNode._set_child_descriptions refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| else: | ||
| sums = np.sum(predictions, axis=1) | ||
| # This can't happen because nodes with 0 instances are prohibited | ||
| # zeros = (sums == 0) | ||
| # predictions[zeros] = 1 | ||
| # sums[zeros] = predictions.shape[1] | ||
| return predictions / sums[:, np.newaxis] | ||
| sums = np.sum(predictions, axis=1) | ||
| # This can't happen because nodes with 0 instances are prohibited | ||
| # zeros = (sums == 0) | ||
| # predictions[zeros] = 1 | ||
| # sums[zeros] = predictions.shape[1] | ||
| return predictions / sums[:, np.newaxis] |
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 TreeModel.predict refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| def get_indices(self, nodes): | ||
| subsets = [node.subset for node in nodes] | ||
| if subsets: | ||
| if subsets := [node.subset for node in nodes]: |
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 TreeModel.get_indices refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| rules.append("{} > {}".format(name, attr.repr_val(lower))) | ||
| rules.append(f"{name} > {attr.repr_val(lower)}") | ||
| elif lower is None: | ||
| rules.append("{} ≤ {}".format(name, attr.repr_val(upper))) | ||
| rules.append(f"{name} ≤ {attr.repr_val(upper)}") | ||
| else: | ||
| rules.append("{} < {} ≤ {}".format( | ||
| attr.repr_val(lower), name, attr.repr_val(upper))) | ||
| rules.append(f"{attr.repr_val(lower)} < {name} ≤ {attr.repr_val(upper)}") | ||
| else: | ||
| rules.append("{}: {}".format(name, node.description)) | ||
| rules.append(f"{name}: {node.description}") |
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 TreeModel.rule refactored with the following changes:
- Replace call to format with f-string [×4] (
use-fstring-for-formatting)
| 'old behavior' | ||
| """ | ||
| alternative = ('; Instead, use ' + obj) if isinstance(obj, str) else '' | ||
| alternative = f'; Instead, use {obj}' if isinstance(obj, str) else '' |
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 deprecated refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| if ret == Model.Value: | ||
| return vals | ||
| else: | ||
| return vals, cal_probs | ||
| return vals if ret == Model.Value else (vals, cal_probs) |
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 CalibratedClassifier.__call__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| calibrators = [fitter.fit(cls_probs, ytrue) | ||
| for cls_idx, cls_probs in enumerate(probabilities.T)] | ||
| calibrators = [fitter.fit(cls_probs, ytrue) for cls_probs in probabilities.T] |
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 CalibratedLearner.get_model refactored with the following changes:
- Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
| solver = "liblinear" | ||
| else: | ||
| solver = "lbfgs" | ||
| solver = "liblinear" if penalty == "l1" else "lbfgs" |
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 LogisticRegressionLearner._initialize_wrapped refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
|
|
||
| def __str__(self): | ||
| return 'ConstantModel {}'.format(self.dist) | ||
| return f'ConstantModel {self.dist}' |
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 ConstantModel.__str__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| y *= x.sum() / y.sum() | ||
| lrs = 2 * (x * np.log(x/y)).sum() | ||
| return lrs | ||
| return 2 * (x * np.log(x/y)).sum() |
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 likelihood_ratio_statistic refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| p_cond = dist_sum / p_dist_sum | ||
| if tc is not None: | ||
| p_cond = dist_sum / p_dist_sum | ||
| # p_cond = dist[tc] / p_dist[tc] | ||
| p_true_positive = dist[tc] / dist_sum | ||
| p_class = p_dist[tc] / p_dist_sum | ||
| else: | ||
| # generality of the rule | ||
| p_cond = dist_sum / p_dist_sum |
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 WeightedRelativeAccuracyEvaluator.evaluate_rule refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if)
This removes the following comments ( why? ):
# generality of the rule
| # remove redundant selectors | ||
| possible_selectors = [smh for smh in possible_selectors if | ||
| smh not in existing_selectors] | ||
|
|
||
| return possible_selectors | ||
| return [smh for smh in possible_selectors if smh not in existing_selectors] |
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 TopDownSearchStrategy.find_new_selectors refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# remove redundant selectors
| attributes = self.domain.attributes | ||
| class_var = self.domain.class_var | ||
|
|
||
| if self.selectors: | ||
| attributes = self.domain.attributes |
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 Rule.__str__ refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
| if not rule_list or rule_list and rule_list[-1].length > 0: | ||
| if not rule_list or rule_list[-1].length > 0: |
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 CN2Learner.fit_storage refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| if len(data.domain.class_vars) != 1: | ||
| n_cls = len(data.domain.class_vars) | ||
| raise ValueError("Number of classes should be 1: {}".format(n_cls)) | ||
| raise ValueError(f"Number of classes should be 1: {n_cls}") |
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 SimpleTreeModel.__init__ refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| depths = {} | ||
| depths[cluster] = 0 | ||
| depths = {cluster: 0} | ||
| for cluster in preorder(cluster): | ||
| cl_depth = depths[cluster] | ||
| depths.update(dict.fromkeys(cluster.branches, cl_depth + 1)) | ||
| depths |= dict.fromkeys(cluster.branches, cl_depth + 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 cluster_depths refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign) - Merge dictionary updates via the union operator (
dict-assign-update-to-union)
| indices.update(chain.from_iterable( | ||
| ((var, -1-idx), (var.name, -1-idx), (-1-idx, -1-idx)) | ||
| for idx, var in enumerate(self.metas))) | ||
| indices |= chain.from_iterable( | ||
| ((var, -1 - idx), (var.name, -1 - idx), (-1 - idx, -1 - idx)) | ||
| for idx, var in enumerate(self.metas) | ||
| ) |
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 Domain._ensure_indices refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union)
| return base if not places \ | ||
| else "{} {:0{}}".format(base, index + 1, places) | ||
| return "{} {:0{}}".format(base, index + 1, places) if places else base |
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 Domain.from_numpy refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression)
| myvar = self.variables[index] | ||
| else: | ||
| myvar = self.metas[-1 - index] | ||
| myvar = self.variables[index] if index >= 0 else self.metas[-1 - index] |
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 Domain._get_equivalent refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if index >= 0: | ||
| return self.variables[index] | ||
| else: | ||
| return self.metas[-1 - index] | ||
| return self.variables[index] if index >= 0 else self.metas[-1 - index] |
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 Domain.__getitem__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.01%.
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
masterrefactored 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
masterbranch, then run:Help us improve this pull request!