-
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
| if years_experience < 3.0: | ||
| if years_experience < 3.0 or years_experience >= 8.5: | ||
| return "paid" | ||
| elif years_experience < 8.5: | ||
| return "unpaid" | ||
| else: | ||
| return "paid" |
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 predict_paid_or_unpaid refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if)
| def load_data(filepath): | ||
| data = pd.read_csv(filepath) | ||
| return data | ||
| return pd.read_csv(filepath) |
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 load_data refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| dataset = list() | ||
| dataset = [] | ||
| with open(filename, 'r') as file: | ||
| csv_reader = reader(file) | ||
| for row in csv_reader: | ||
| if not row: | ||
| continue | ||
| dataset.append(row) | ||
|
|
||
| dataset.extend(row for row in csv_reader if row) |
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 load_csv refactored with the following changes:
- Replace list() with [] (
list-literal) - Replace a for append loop with list extend (
for-append-to-extend) - Lift code into else after jump in control flow (
reintroduce-else) - Remove redundant continue statement (
remove-redundant-continue)
| lookup = dict() | ||
|
|
||
| for i, value in enumerate(unique): | ||
| lookup[value] = i | ||
| lookup = {value: i for i, value in enumerate(unique)} |
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 str_columm_to_int refactored with the following changes:
- Replace dict() with {} (
dict-literal) - Convert for loop into dictionary comprehension (
dict-comprehension)
| dataset_split = list() | ||
| dataset_split = [] | ||
| dataset_copy = list(dataset) | ||
| fold_size = int(len(dataset) / k_folds) | ||
|
|
||
| for i in range(k_folds): | ||
| fold = list() | ||
| for _ in range(k_folds): | ||
| fold = [] |
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 cross_validation_split refactored with the following changes:
- Replace list() with [] (
list-literal) - Replace unused for index with underscore (
for-index-underscore)
| else: | ||
| # if even, return the average of the middle values | ||
| lo = midpoint - 1 | ||
| hi = midpoint | ||
| return (sorted_v[lo] + sorted_v[hi]) / 2 | ||
| # if even, return the average of the middle values | ||
| lo = midpoint - 1 | ||
| hi = midpoint | ||
| return (sorted_v[lo] + sorted_v[hi]) / 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 median refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| i_points = [p for p, a in zip(inputs, assignments) if a == i] | ||
|
|
||
| if i_points: | ||
| if i_points := [p for p, a in zip(inputs, assignments) if a == i]: |
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 KMeans.train refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| if is_leaf(cluster): | ||
| return float('inf') | ||
| else: | ||
| return cluster[0] | ||
| return float('inf') if is_leaf(cluster) else cluster[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 get_merge_order refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| clusters = [input for input in inputs] | ||
| clusters = list(inputs) | ||
|
|
||
| # as long as we have more than one cluster left... | ||
| while len(clusters) > 1: | ||
| # find the two closest clusters | ||
| c1, c2 = min([(cluster1, cluster2) | ||
| for i, cluster1 in enumerate(clusters) | ||
| for cluster2 in clusters[:i]], | ||
| key=lambda p: cluster_distance(p[0], p[1], distance_agg)) | ||
| c1, c2 = min( | ||
| ( | ||
| (cluster1, cluster2) | ||
| for i, cluster1 in enumerate(clusters) | ||
| for cluster2 in clusters[:i] | ||
| ), | ||
| key=lambda p: cluster_distance(p[0], p[1], distance_agg), | ||
| ) | ||
|
|
||
|
|
||
| # remove them from the list of clusters | ||
| clusters = [c for c in clusters if c != c1 and c != c2] | ||
| clusters = [c for c in clusters if c not in [c1, c2]] |
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 bottom_up_cluster refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension) - Replace unneeded comprehension with generator (
comprehension-to-generator) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| return winner # unique winner, so return it | ||
| else: | ||
| return majority_vote(labels[:-1]) # try again without the farthest | ||
| return winner if num_winners == 1 else majority_vote(labels[:-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 majority_vote refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# unique winner, so return it
# try again without the farthest
| plt.title(str(k) + "-Nearest Neighbor Programming Languages") | ||
| plt.title(f'{str(k)}-Nearest Neighbor Programming Languages') |
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 classify_and_plot_grid refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| def estimate_beta(x, y): | ||
| beta_initial = [random.random() for x_i in x[0]] | ||
| beta_initial = [random.random() for _ in x[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 estimate_beta refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| """use gradient descent to fit a ridge regression | ||
| with penalty alpha""" | ||
| beta_initial = [random.random() for x_i in x[0]] | ||
| beta_initial = [random.random() for _ in x[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 estimate_beta_ridge refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| return random.randrange(1, y) | ||
| else: | ||
| return random.randrange(y - 6, 7) | ||
| return random.randrange(1, y) if y <= 7 else random.randrange(y - 6, 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 random_x_given_y refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| distinct_words = set(word | ||
| for document in documents | ||
| for word in document) | ||
| distinct_words = {word for document in documents for word in document} |
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 174-176 refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| document_topics = [[random.randrange(K) for word in document] | ||
| for document in documents] | ||
| document_topics = [ | ||
| [random.randrange(K) for _ in document] for document in documents | ||
| ] | ||
|
|
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 206-215 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| return try_or_none(parser)(value) | ||
| else: | ||
| return value | ||
| return try_or_none(parser)(value) if parser is not None else value |
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 try_parse_field 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.12%.
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!