Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (TheAlgorithms#11275)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.1.14 → v0.2.0](astral-sh/ruff-pre-commit@v0.1.14...v0.2.0)

* Upgrade pyproject.toml

* Revert sudoku_solver.py RUF017 Avoid quadratic list summation

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
  • Loading branch information
pre-commit-ci[bot] and cclauss committed Feb 5, 2024
1 parent 4128f19 commit ed8d920
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 39 deletions.
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.1.14
rev: v0.2.0
hooks:
- id: ruff
- id: ruff-format
Expand Down
2 changes: 1 addition & 1 deletion ciphers/mixed_keyword_cypher.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def mixed_keyword(
if verbose:
print(mapping)
# create the encrypted text by mapping the plaintext to the modified alphabet
return "".join(mapping[char] if char in mapping else char for char in plaintext)
return "".join(mapping.get(char, char) for char in plaintext)


if __name__ == "__main__":
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 @@ -22,7 +22,7 @@ def cross(items_a, items_b):
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
)
units = {s: [u for u in unitlist if s in u] for s in squares}
peers = {s: set(sum(units[s], [])) - {s} for s in squares}
peers = {s: set(sum(units[s], [])) - {s} for s in squares} # noqa: RUF017


def test():
Expand Down
4 changes: 1 addition & 3 deletions data_structures/linked_list/is_palindrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,9 @@ def is_palindrome_dict(head: ListNode | None) -> bool:
if len(v) % 2 != 0:
middle += 1
else:
step = 0
for i in range(len(v)):
for step, i in enumerate(range(len(v))):
if v[i] + v[len(v) - 1 - step] != checksum:
return False
step += 1
if middle > 1:
return False
return True
Expand Down
4 changes: 1 addition & 3 deletions digital_image_processing/filters/gaussian_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ def gaussian_filter(image, k_size, sigma):

# im2col, turn the k_size*k_size pixels into a row and np.vstack all rows
image_array = zeros((dst_height * dst_width, k_size * k_size))
row = 0
for i, j in product(range(dst_height), range(dst_width)):
for row, (i, j) in enumerate(product(range(dst_height), range(dst_width))):
window = ravel(image[i : i + k_size, j : j + k_size])
image_array[row, :] = window
row += 1

# turn the kernel into shape(k*k, 1)
gaussian_kernel = gen_gaussian_kernel(k_size, sigma)
Expand Down
8 changes: 2 additions & 6 deletions electronics/resistor_equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ def resistor_parallel(resistors: list[float]) -> float:
"""

first_sum = 0.00
index = 0
for resistor in resistors:
for index, resistor in enumerate(resistors):
if resistor <= 0:
msg = f"Resistor at index {index} has a negative or zero value!"
raise ValueError(msg)
first_sum += 1 / float(resistor)
index += 1
return 1 / first_sum


Expand All @@ -44,13 +42,11 @@ def resistor_series(resistors: list[float]) -> float:
ValueError: Resistor at index 2 has a negative value!
"""
sum_r = 0.00
index = 0
for resistor in resistors:
for index, resistor in enumerate(resistors):
sum_r += resistor
if resistor < 0:
msg = f"Resistor at index {index} has a negative value!"
raise ValueError(msg)
index += 1
return sum_r


Expand Down
18 changes: 6 additions & 12 deletions hashes/hamming_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,14 @@ def emitter_converter(size_par, data):
# Bit counter one for a given parity
cont_bo = 0
# counter to control the loop reading
cont_loop = 0
for x in data_ord:
for cont_loop, x in enumerate(data_ord):
if x is not None:
try:
aux = (bin_pos[cont_loop])[-1 * (bp)]
except IndexError:
aux = "0"
if aux == "1" and x == "1":
cont_bo += 1
cont_loop += 1
parity.append(cont_bo % 2)

qtd_bp += 1
Expand Down Expand Up @@ -164,21 +162,20 @@ def receptor_converter(size_par, data):
parity_received = []
data_output = []

for x in range(1, len(data) + 1):
for i, item in enumerate(data, 1):
# Performs a template of bit positions - who should be given,
# and who should be parity
if qtd_bp < size_par and (np.log(x) / np.log(2)).is_integer():
if qtd_bp < size_par and (np.log(i) / np.log(2)).is_integer():
data_out_gab.append("P")
qtd_bp = qtd_bp + 1
else:
data_out_gab.append("D")

# Sorts the data to the new output size
if data_out_gab[-1] == "D":
data_output.append(data[cont_data])
data_output.append(item)
else:
parity_received.append(data[cont_data])
cont_data += 1
parity_received.append(item)

# -----------calculates the parity with the data
data_out = []
Expand Down Expand Up @@ -215,17 +212,14 @@ def receptor_converter(size_par, data):
for bp in range(1, size_par + 1):
# Bit counter one for a certain parity
cont_bo = 0
# Counter to control loop reading
cont_loop = 0
for x in data_ord:
for cont_loop, x in enumerate(data_ord):
if x is not None:
try:
aux = (bin_pos[cont_loop])[-1 * (bp)]
except IndexError:
aux = "0"
if aux == "1" and x == "1":
cont_bo += 1
cont_loop += 1
parity.append(str(cont_bo % 2))

qtd_bp += 1
Expand Down
2 changes: 1 addition & 1 deletion machine_learning/k_means_clust.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def report_generator(
[
("sum", "sum"),
("mean_with_zeros", lambda x: np.mean(np.nan_to_num(x))),
("mean_without_zeros", lambda x: x.replace(0, np.NaN).mean()),
("mean_without_zeros", lambda x: x.replace(0, np.nan).mean()),
(
"mean_25-75",
lambda x: np.mean(
Expand Down
2 changes: 1 addition & 1 deletion machine_learning/sequential_minimum_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def plot_partition_boundary(
ax.contour(
xrange,
yrange,
np.mat(grid).T,
np.asmatrix(grid).T,
levels=(-1, 0, 1),
linestyles=("--", "-", "--"),
linewidths=(1, 1, 1),
Expand Down
6 changes: 3 additions & 3 deletions neural_network/convolution_neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def __init__(
self.rate_weight = rate_w
self.rate_thre = rate_t
self.w_conv1 = [
np.mat(-1 * np.random.rand(self.conv1[0], self.conv1[0]) + 0.5)
np.asmatrix(-1 * np.random.rand(self.conv1[0], self.conv1[0]) + 0.5)
for i in range(self.conv1[1])
]
self.wkj = np.mat(-1 * np.random.rand(self.num_bp3, self.num_bp2) + 0.5)
self.vji = np.mat(-1 * np.random.rand(self.num_bp2, self.num_bp1) + 0.5)
self.wkj = np.asmatrix(-1 * np.random.rand(self.num_bp3, self.num_bp2) + 0.5)
self.vji = np.asmatrix(-1 * np.random.rand(self.num_bp2, self.num_bp1) + 0.5)
self.thre_conv1 = -2 * np.random.rand(self.conv1[1]) + 1
self.thre_bp2 = -2 * np.random.rand(self.num_bp2) + 1
self.thre_bp3 = -2 * np.random.rand(self.num_bp3) + 1
Expand Down
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.ruff]
ignore = [ # `ruff rule S101` for a description of that rule
lint.ignore = [ # `ruff rule S101` for a description of that rule
"ARG001", # Unused function argument `amount` -- FIX ME?
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` -- FIX ME
"B905", # `zip()` without an explicit `strict=` parameter -- FIX ME
Expand Down Expand Up @@ -31,7 +31,7 @@ ignore = [ # `ruff rule S101` for a description of that rule
"SLF001", # Private member accessed: `_Iterator` -- FIX ME
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
]
select = [ # https://beta.ruff.rs/docs/rules
lint.select = [ # https://beta.ruff.rs/docs/rules
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"ASYNC", # flake8-async
Expand Down Expand Up @@ -84,13 +84,13 @@ select = [ # https://beta.ruff.rs/docs/rules
# "TCH", # flake8-type-checking
# "TRY", # tryceratops
]
show-source = true
target-version = "py311"
output-format = "full"
target-version = "py312"

[tool.ruff.mccabe] # DO NOT INCREASE THIS VALUE
[tool.ruff.lint.mccabe] # DO NOT INCREASE THIS VALUE
max-complexity = 17 # default: 10

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"arithmetic_analysis/newton_raphson.py" = ["PGH001"]
"audio_filters/show_response.py" = ["ARG002"]
"data_structures/binary_tree/binary_search_tree_recursive.py" = ["BLE001"]
Expand All @@ -110,7 +110,7 @@ max-complexity = 17 # default: 10
"project_euler/problem_099/sol1.py" = ["SIM115"]
"sorts/external_sort.py" = ["SIM115"]

[tool.ruff.pylint] # DO NOT INCREASE THESE VALUES
[tool.ruff.lint.pylint] # DO NOT INCREASE THESE VALUES
allow-magic-value-types = ["float", "int", "str"]
max-args = 10 # default: 5
max-branches = 20 # default: 12
Expand Down

0 comments on commit ed8d920

Please sign in to comment.