Skip to content

Commit 7b69bf5

Browse files
M-H-JishanM-H-Jishan
authored andcommitted
Fix ruff linting errors
- Fix ambiguous minus sign in B-Tree docstring - Import Hashable from collections.abc instead of typing - Remove unused numpy import from gaussian_naive_bayes.py - Prefix unused fig variables with underscore in ML files - Rename unused loop variable i to _i in rabin_karp_search.py - Combine nested if statements in rabin_karp_search.py All ruff checks now pass for contributed files.
1 parent ed60a0b commit 7b69bf5

File tree

6 files changed

+7
-9
lines changed

6 files changed

+7
-9
lines changed

data_structures/binary_tree/b_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BTree:
6363
- Every non-leaf node (except root) has at least ⌈m/2⌉ children
6464
- The root has at least 2 children if it is not a leaf
6565
- All leaves appear on the same level
66-
- A non-leaf node with k children contains k1 keys
66+
- A non-leaf node with k children contains k-1 keys
6767
6868
Examples:
6969
>>> btree = BTree(order=3)

graphs/check_bipartite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import defaultdict, deque
2-
from typing import Hashable
2+
from collections.abc import Hashable
33

44

55
def is_bipartite_dfs(graph: dict[Hashable, list[Hashable]]) -> bool:

machine_learning/gaussian_naive_bayes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
on the Iris dataset with proper visualization using modern sklearn methods.
66
"""
77

8-
import numpy as np
98
from sklearn.datasets import load_iris
109
from sklearn.metrics import ConfusionMatrixDisplay, accuracy_score
1110
from sklearn.model_selection import train_test_split

machine_learning/gradient_boosting_regressor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def main() -> None:
5252
print(f"Mean squared error: {mean_squared_error(y_test, y_pred):.2f}")
5353
print(f"Test R² score: {r2_score(y_test, y_pred):.2f}")
5454

55-
fig, ax = plt.subplots()
55+
_fig, ax = plt.subplots()
5656
ax.scatter(y_test, y_pred, edgecolors=(0, 0, 0), alpha=0.4)
5757
ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], "r--", lw=3)
5858
ax.set_xlabel("Actual")

machine_learning/random_forest_regressor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def main() -> None:
5252
print(f"Mean squared error: {mean_squared_error(y_test, y_pred):.2f}")
5353
print(f"Test R² score: {r2_score(y_test, y_pred):.2f}")
5454

55-
fig, ax = plt.subplots()
55+
_fig, ax = plt.subplots()
5656
ax.scatter(y_test, y_pred, edgecolors=(0, 0, 0), alpha=0.4)
5757
ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], "r--", lw=3)
5858
ax.set_xlabel("Actual")

strings/rabin_karp_search.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,16 @@ def rabin_karp_search(text: str, pattern: str, prime: int = 101) -> list[int]:
5454
h = 1
5555
results: list[int] = []
5656

57-
for i in range(m - 1):
57+
for _i in range(m - 1):
5858
h = (h * d) % prime
5959

6060
for i in range(m):
6161
pattern_hash = (d * pattern_hash + ord(pattern[i])) % prime
6262
text_hash = (d * text_hash + ord(text[i])) % prime
6363

6464
for i in range(n - m + 1):
65-
if pattern_hash == text_hash:
66-
if text[i : i + m] == pattern:
67-
results.append(i)
65+
if pattern_hash == text_hash and text[i : i + m] == pattern:
66+
results.append(i)
6867

6968
if i < n - m:
7069
text_hash = (d * (text_hash - ord(text[i]) * h) + ord(text[i + m])) % prime

0 commit comments

Comments
 (0)