Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: auto-walrus

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.12
rev: v0.13.0
hooks:
- id: ruff-check
- id: ruff-format
Expand Down
2 changes: 1 addition & 1 deletion data_structures/arrays/sudoku_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def search(values):
if all(len(values[s]) == 1 for s in squares):
return values ## Solved!
## Chose the unfilled square s with the fewest possibilities
n, s = min((len(values[s]), s) for s in squares if len(values[s]) > 1)
_n, s = min((len(values[s]), s) for s in squares if len(values[s]) > 1)
return some(search(assign(values.copy(), s, d)) for d in values[s])


Expand Down
4 changes: 2 additions & 2 deletions data_structures/trie/radix_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def find(self, word: str) -> bool:
if not incoming_node:
return False
else:
matching_string, remaining_prefix, remaining_word = incoming_node.match(
_matching_string, remaining_prefix, remaining_word = incoming_node.match(
word
)
# If there is remaining prefix, the word can't be on the tree
Expand Down Expand Up @@ -144,7 +144,7 @@ def delete(self, word: str) -> bool:
if not incoming_node:
return False
else:
matching_string, remaining_prefix, remaining_word = incoming_node.match(
_matching_string, remaining_prefix, remaining_word = incoming_node.match(
word
)
# If there is remaining prefix, the word can't be on the tree
Expand Down
10 changes: 5 additions & 5 deletions graphs/graph_adjacency_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def test_remove_edge(self) -> None:
(
undirected_graph,
directed_graph,
random_vertices,
_random_vertices,
random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

Expand Down Expand Up @@ -502,7 +502,7 @@ def test_add_vertex_exception_check(self) -> None:
undirected_graph,
directed_graph,
random_vertices,
random_edges,
_random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

for vertex in random_vertices:
Expand All @@ -516,7 +516,7 @@ def test_remove_vertex_exception_check(self) -> None:
undirected_graph,
directed_graph,
random_vertices,
random_edges,
_random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

for i in range(101):
Expand All @@ -530,7 +530,7 @@ def test_add_edge_exception_check(self) -> None:
(
undirected_graph,
directed_graph,
random_vertices,
_random_vertices,
random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

Expand Down Expand Up @@ -569,7 +569,7 @@ def test_contains_edge_exception_check(self) -> None:
undirected_graph,
directed_graph,
random_vertices,
random_edges,
_random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

for vertex in random_vertices:
Expand Down
10 changes: 5 additions & 5 deletions graphs/graph_adjacency_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def test_remove_edge(self) -> None:
(
undirected_graph,
directed_graph,
random_vertices,
_random_vertices,
random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

Expand Down Expand Up @@ -523,7 +523,7 @@ def test_add_vertex_exception_check(self) -> None:
undirected_graph,
directed_graph,
random_vertices,
random_edges,
_random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

for vertex in random_vertices:
Expand All @@ -537,7 +537,7 @@ def test_remove_vertex_exception_check(self) -> None:
undirected_graph,
directed_graph,
random_vertices,
random_edges,
_random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

for i in range(101):
Expand All @@ -551,7 +551,7 @@ def test_add_edge_exception_check(self) -> None:
(
undirected_graph,
directed_graph,
random_vertices,
_random_vertices,
random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

Expand Down Expand Up @@ -590,7 +590,7 @@ def test_contains_edge_exception_check(self) -> None:
undirected_graph,
directed_graph,
random_vertices,
random_edges,
_random_edges,
) = self.__generate_graphs(20, 0, 100, 4)

for vertex in random_vertices:
Expand Down
12 changes: 7 additions & 5 deletions knapsack/tests/test_greedy_knapsack.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_negative_max_weight(self):
# profit = [10, 20, 30, 40, 50, 60]
# weight = [2, 4, 6, 8, 10, 12]
# max_weight = -15
pytest.raises(ValueError, match="max_weight must greater than zero.")
pytest.raises(ValueError, match=r"max_weight must greater than zero.")

def test_negative_profit_value(self):
"""
Expand All @@ -38,7 +38,7 @@ def test_negative_profit_value(self):
# profit = [10, -20, 30, 40, 50, 60]
# weight = [2, 4, 6, 8, 10, 12]
# max_weight = 15
pytest.raises(ValueError, match="Weight can not be negative.")
pytest.raises(ValueError, match=r"Weight can not be negative.")

def test_negative_weight_value(self):
"""
Expand All @@ -48,7 +48,7 @@ def test_negative_weight_value(self):
# profit = [10, 20, 30, 40, 50, 60]
# weight = [2, -4, 6, -8, 10, 12]
# max_weight = 15
pytest.raises(ValueError, match="Profit can not be negative.")
pytest.raises(ValueError, match=r"Profit can not be negative.")

def test_null_max_weight(self):
"""
Expand All @@ -58,7 +58,7 @@ def test_null_max_weight(self):
# profit = [10, 20, 30, 40, 50, 60]
# weight = [2, 4, 6, 8, 10, 12]
# max_weight = null
pytest.raises(ValueError, match="max_weight must greater than zero.")
pytest.raises(ValueError, match=r"max_weight must greater than zero.")

def test_unequal_list_length(self):
"""
Expand All @@ -68,7 +68,9 @@ def test_unequal_list_length(self):
# profit = [10, 20, 30, 40, 50]
# weight = [2, 4, 6, 8, 10, 12]
# max_weight = 100
pytest.raises(IndexError, match="The length of profit and weight must be same.")
pytest.raises(
IndexError, match=r"The length of profit and weight must be same."
)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion linear_algebra/gaussian_elimination.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def retroactive_resolution(
[ 0.5]])
"""

rows, columns = np.shape(coefficients)
rows, _columns = np.shape(coefficients)

x: NDArray[float64] = np.zeros((rows, 1), dtype=float)
for row in reversed(range(rows)):
Expand Down
4 changes: 2 additions & 2 deletions linear_algebra/jacobi_iteration_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def jacobi_iteration_method(
(coefficient_matrix, constant_matrix), axis=1
)

rows, cols = table.shape
rows, _cols = table.shape

strictly_diagonally_dominant(table)

Expand Down Expand Up @@ -149,7 +149,7 @@ def jacobi_iteration_method(

# Here we get 'i_col' - these are the column numbers, for each row
# without diagonal elements, except for the last column.
i_row, i_col = np.where(masks)
_i_row, i_col = np.where(masks)
ind = i_col.reshape(-1, rows - 1)

#'i_col' is converted to a two-dimensional list 'ind', which will be
Expand Down
2 changes: 1 addition & 1 deletion machine_learning/polynomial_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _design_matrix(data: np.ndarray, degree: int) -> np.ndarray:
...
ValueError: Data must have dimensions N x 1
"""
rows, *remaining = data.shape
_rows, *remaining = data.shape
if remaining:
raise ValueError("Data must have dimensions N x 1")

Expand Down
2 changes: 1 addition & 1 deletion machine_learning/principle_component_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def main() -> None:
"""
Driver function to execute PCA and display results.
"""
data_x, data_y = collect_dataset()
data_x, _data_y = collect_dataset()

# Number of principal components to retain
n_components = 2
Expand Down
2 changes: 1 addition & 1 deletion maths/chinese_remainder_theorem.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def invert_modulo(a: int, n: int) -> int:
1

"""
(b, x) = extended_euclid(a, n)
(b, _x) = extended_euclid(a, n)
if b < 0:
b = (b % n + n) % n
return b
Expand Down
4 changes: 2 additions & 2 deletions maths/modular_division.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def modular_division(a: int, b: int, n: int) -> int:
assert n > 1
assert a > 0
assert greatest_common_divisor(a, n) == 1
(d, t, s) = extended_gcd(n, a) # Implemented below
(_d, _t, s) = extended_gcd(n, a) # Implemented below
x = (b * s) % n
return x

Expand All @@ -47,7 +47,7 @@ def invert_modulo(a: int, n: int) -> int:
1

"""
(b, x) = extended_euclid(a, n) # Implemented below
(b, _x) = extended_euclid(a, n) # Implemented below
if b < 0:
b = (b % n + n) % n
return b
Expand Down
4 changes: 2 additions & 2 deletions neural_network/convolution_neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def predict(self, datas_test):
print((" - - Shape: Test_Data ", np.shape(datas_test)))
for p in range(len(datas_test)):
data_test = np.asmatrix(datas_test[p])
data_focus1, data_conved1 = self.convolute(
_data_focus1, data_conved1 = self.convolute(
data_test,
self.conv1,
self.w_conv1,
Expand All @@ -339,7 +339,7 @@ def predict(self, datas_test):
def convolution(self, data):
# return the data of image after convoluting process so we can check it out
data_test = np.asmatrix(data)
data_focus1, data_conved1 = self.convolute(
_data_focus1, data_conved1 = self.convolute(
data_test,
self.conv1,
self.w_conv1,
Expand Down
2 changes: 1 addition & 1 deletion project_euler/problem_551/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def solution(n: int = 10**15) -> int:
i = 1
dn = 0
while True:
diff, terms_jumped = next_term(digits, 20, i + dn, n)
_diff, terms_jumped = next_term(digits, 20, i + dn, n)
dn += terms_jumped
if dn == n - i:
break
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ lint.ignore = [
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes -- FIX ME
"SIM905", # Consider using a list literal instead of `str.split` -- DO NOT FIX
"SLF001", # Private member accessed: `_Iterator` -- FIX ME
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
]

lint.per-file-ignores."data_structures/hashing/tests/test_hash_map.py" = [
Expand Down
2 changes: 1 addition & 1 deletion scheduling/multi_level_feedback_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def multi_level_feedback_queue(self) -> deque[Process]:

# all queues except last one have round_robin algorithm
for i in range(self.number_of_queues - 1):
finished, self.ready_queue = self.round_robin(
_finished, self.ready_queue = self.round_robin(
self.ready_queue, self.time_slices[i]
)
# the last queue has first_come_first_served algorithm
Expand Down