Skip to content

Commit 8fbd7cb

Browse files
committed
Fix review issue
1 parent 79bdca3 commit 8fbd7cb

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

data_structures/heap/max_heap.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def insert(self, value: int) -> None:
3838
def __swap_down(self, i: int) -> None:
3939
"""Swap the element down"""
4040
while self.__size >= 2 * i:
41-
if 2 * i + 1 > self.__size or self.__heap[2 * i] > self.__heap[2 * i + 1]:
41+
if 2 * i + 1 > self.__size: # noqa: SIM114
42+
bigger_child = 2 * i
43+
elif self.__heap[2 * i] > self.__heap[2 * i + 1]:
4244
bigger_child = 2 * i
4345
else:
4446
bigger_child = 2 * i + 1

graphs/minimum_spanning_tree_prims.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def top_to_bottom(self, heap, start, size, positions):
1616
if start > size // 2 - 1:
1717
return
1818
else:
19-
if 2 * start + 2 >= size or heap[2 * start + 1] < heap[2 * start + 2]:
19+
if 2 * start + 2 >= size: # noqa: SIM114
20+
smallest_child = 2 * start + 1
21+
elif heap[2 * start + 1] < heap[2 * start + 2]:
2022
smallest_child = 2 * start + 1
2123
else:
2224
smallest_child = 2 * start + 2

machine_learning/decision_tree.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def train(self, x, y):
105105
the predictor
106106
"""
107107
for i in range(len(x)):
108-
if len(x[:i]) < self.min_leaf_size or len(x[i:]) < self.min_leaf_size:
108+
if len(x[:i]) < self.min_leaf_size: # noqa: SIM114
109+
continue
110+
elif len(x[i:]) < self.min_leaf_size:
109111
continue
110112
else:
111113
error_left = self.mean_squared_error(x[:i], np.mean(y[:i]))

matrix/sherman_morrison.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def validate_indices(self, loc: tuple[int, int]) -> bool:
6565
>>> a.validate_indices((0, 0))
6666
True
6767
"""
68-
if not (isinstance(loc, (list, tuple)) and len(loc) == 2) or not (
69-
0 <= loc[0] < self.row and 0 <= loc[1] < self.column
70-
):
68+
if not (isinstance(loc, (list, tuple)) and len(loc) == 2): # noqa: SIM114
69+
return False
70+
elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
7171
return False
7272
else:
7373
return True

0 commit comments

Comments
 (0)