Skip to content

Commit 1faf10b

Browse files
CaedenPHgithub-actions
and
github-actions
authored
Correct ruff failures (TheAlgorithms#8732)
* fix: Correct ruff problems * updating DIRECTORY.md * fix: Fix pre-commit errors * updating DIRECTORY.md --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 793e564 commit 1faf10b

File tree

9 files changed

+22
-20
lines changed

9 files changed

+22
-20
lines changed

DIRECTORY.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@
294294
* [Mergesort](divide_and_conquer/mergesort.py)
295295
* [Peak](divide_and_conquer/peak.py)
296296
* [Power](divide_and_conquer/power.py)
297-
* [Strassen Matrix Multiplication](divide_and_conquer/strassen_matrix_multiplication.py)
298297

299298
## Dynamic Programming
300299
* [Abbreviation](dynamic_programming/abbreviation.py)
@@ -632,6 +631,7 @@
632631
* [Radians](maths/radians.py)
633632
* [Radix2 Fft](maths/radix2_fft.py)
634633
* [Relu](maths/relu.py)
634+
* [Remove Digit](maths/remove_digit.py)
635635
* [Runge Kutta](maths/runge_kutta.py)
636636
* [Segmented Sieve](maths/segmented_sieve.py)
637637
* Series
@@ -694,6 +694,8 @@
694694

695695
## Neural Network
696696
* [2 Hidden Layers Neural Network](neural_network/2_hidden_layers_neural_network.py)
697+
* Activation Functions
698+
* [Exponential Linear Unit](neural_network/activation_functions/exponential_linear_unit.py)
697699
* [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py)
698700
* [Convolution Neural Network](neural_network/convolution_neural_network.py)
699701
* [Input Data](neural_network/input_data.py)
@@ -1080,6 +1082,7 @@
10801082

10811083
## Sorts
10821084
* [Bead Sort](sorts/bead_sort.py)
1085+
* [Binary Insertion Sort](sorts/binary_insertion_sort.py)
10831086
* [Bitonic Sort](sorts/bitonic_sort.py)
10841087
* [Bogo Sort](sorts/bogo_sort.py)
10851088
* [Bubble Sort](sorts/bubble_sort.py)
@@ -1170,6 +1173,7 @@
11701173
* [Reverse Words](strings/reverse_words.py)
11711174
* [Snake Case To Camel Pascal Case](strings/snake_case_to_camel_pascal_case.py)
11721175
* [Split](strings/split.py)
1176+
* [String Switch Case](strings/string_switch_case.py)
11731177
* [Text Justification](strings/text_justification.py)
11741178
* [Top K Frequent Words](strings/top_k_frequent_words.py)
11751179
* [Upper](strings/upper.py)

conversions/prefix_conversions_string.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def add_si_prefix(value: float) -> str:
9696
for name_prefix, value_prefix in prefixes.items():
9797
numerical_part = value / (10**value_prefix)
9898
if numerical_part > 1:
99-
return f"{str(numerical_part)} {name_prefix}"
99+
return f"{numerical_part!s} {name_prefix}"
100100
return str(value)
101101

102102

@@ -111,7 +111,7 @@ def add_binary_prefix(value: float) -> str:
111111
for prefix in BinaryUnit:
112112
numerical_part = value / (2**prefix.value)
113113
if numerical_part > 1:
114-
return f"{str(numerical_part)} {prefix.name}"
114+
return f"{numerical_part!s} {prefix.name}"
115115
return str(value)
116116

117117

conversions/rgb_hsv_conversion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def rgb_to_hsv(red: int, green: int, blue: int) -> list[float]:
121121
float_red = red / 255
122122
float_green = green / 255
123123
float_blue = blue / 255
124-
value = max(max(float_red, float_green), float_blue)
125-
chroma = value - min(min(float_red, float_green), float_blue)
124+
value = max(float_red, float_green, float_blue)
125+
chroma = value - min(float_red, float_green, float_blue)
126126
saturation = 0 if value == 0 else chroma / value
127127

128128
if chroma == 0:

digital_image_processing/test_digital_image_processing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_nearest_neighbour(
9696

9797

9898
def test_local_binary_pattern():
99-
file_path: str = "digital_image_processing/image_data/lena.jpg"
99+
file_path = "digital_image_processing/image_data/lena.jpg"
100100

101101
# Reading the image and converting it to grayscale.
102102
image = imread(file_path, 0)

divide_and_conquer/strassen_matrix_multiplication.py divide_and_conquer/strassen_matrix_multiplication.py.BROKEN

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def strassen(matrix1: list, matrix2: list) -> list:
122122
if dimension1[0] == dimension1[1] and dimension2[0] == dimension2[1]:
123123
return [matrix1, matrix2]
124124

125-
maximum = max(max(dimension1), max(dimension2))
125+
maximum = max(dimension1, dimension2)
126126
maxim = int(math.pow(2, math.ceil(math.log2(maximum))))
127127
new_matrix1 = matrix1
128128
new_matrix2 = matrix2

dynamic_programming/fibonacci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get(self, index: int) -> list:
2424
return self.sequence[:index]
2525

2626

27-
def main():
27+
def main() -> None:
2828
print(
2929
"Fibonacci Series Using Dynamic Programming\n",
3030
"Enter the index of the Fibonacci number you want to calculate ",

maths/euclidean_distance.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

3+
import typing
34
from collections.abc import Iterable
4-
from typing import Union
55

66
import numpy as np
77

8-
Vector = Union[Iterable[float], Iterable[int], np.ndarray]
9-
VectorOut = Union[np.float64, int, float]
8+
Vector = typing.Union[Iterable[float], Iterable[int], np.ndarray] # noqa: UP007
9+
VectorOut = typing.Union[np.float64, int, float] # noqa: UP007
1010

1111

1212
def euclidean_distance(vector_1: Vector, vector_2: Vector) -> VectorOut:

physics/horizontal_projectile_motion.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,6 @@ def test_motion() -> None:
147147
# Print results
148148
print()
149149
print("Results: ")
150-
print(f"Horizontal Distance: {str(horizontal_distance(init_vel, angle))} [m]")
151-
print(f"Maximum Height: {str(max_height(init_vel, angle))} [m]")
152-
print(f"Total Time: {str(total_time(init_vel, angle))} [s]")
150+
print(f"Horizontal Distance: {horizontal_distance(init_vel, angle)!s} [m]")
151+
print(f"Maximum Height: {max_height(init_vel, angle)!s} [m]")
152+
print(f"Total Time: {total_time(init_vel, angle)!s} [s]")

searches/binary_tree_traversal.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ def __init__(self, data):
1313
self.left = None
1414

1515

16-
def build_tree():
16+
def build_tree() -> TreeNode:
1717
print("\n********Press N to stop entering at any point of time********\n")
18-
check = input("Enter the value of the root node: ").strip().lower() or "n"
19-
if check == "n":
20-
return None
18+
check = input("Enter the value of the root node: ").strip().lower()
2119
q: queue.Queue = queue.Queue()
2220
tree_node = TreeNode(int(check))
2321
q.put(tree_node)
@@ -37,7 +35,7 @@ def build_tree():
3735
right_node = TreeNode(int(check))
3836
node_found.right = right_node
3937
q.put(right_node)
40-
return None
38+
raise
4139

4240

4341
def pre_order(node: TreeNode) -> None:
@@ -272,7 +270,7 @@ def prompt(s: str = "", width=50, char="*") -> str:
272270
doctest.testmod()
273271
print(prompt("Binary Tree Traversals"))
274272

275-
node = build_tree()
273+
node: TreeNode = build_tree()
276274
print(prompt("Pre Order Traversal"))
277275
pre_order(node)
278276
print(prompt() + "\n")

0 commit comments

Comments
 (0)