Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(pre_commit): ⬆ pre_commit autoupdate #1775

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/PyCQA/bandit
rev: '1.8.0'
rev: '1.8.2'
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -48,7 +48,7 @@ repos:
# args: ["--number"]

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ build = ">=0.10,<1.3"

[tool.bandit]
target = ["test", "supervision"]
tests = ["B201", "B301", "B318", "B314", "B303", "B413", "B412", "B410"]
tests = ["B201", "B301", "B318", "B314", "B303", "B413", "B412"]

[tool.autoflake]
check = true
Expand Down
14 changes: 7 additions & 7 deletions supervision/detection/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def from_azure_analyze_image(
"""
if "error" in azure_result:
raise ValueError(
f'Azure API returned an error {azure_result["error"]["message"]}'
f"Azure API returned an error {azure_result['error']['message']}"
)

xyxy, confidences, class_ids = [], [], []
Expand Down Expand Up @@ -1306,9 +1306,9 @@ def with_nms(
if len(self) == 0:
return self

assert (
self.confidence is not None
), "Detections confidence must be given for NMS to be executed."
assert self.confidence is not None, (
"Detections confidence must be given for NMS to be executed."
)

if class_agnostic:
predictions = np.hstack((self.xyxy, self.confidence.reshape(-1, 1)))
Expand Down Expand Up @@ -1362,9 +1362,9 @@ def with_nmm(
if len(self) == 0:
return self

assert (
self.confidence is not None
), "Detections confidence must be given for NMM to be executed."
assert self.confidence is not None, (
"Detections confidence must be given for NMM to be executed."
)

if class_agnostic:
predictions = np.hstack((self.xyxy, self.confidence.reshape(-1, 1)))
Expand Down
12 changes: 6 additions & 6 deletions supervision/detection/lmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@ def from_florence_2(
return xyxy, labels, None, None

if task in ["<REGION_TO_CATEGORY>", "<REGION_TO_DESCRIPTION>"]:
assert isinstance(
result, str
), f"Expected string as <REGION_TO_CATEGORY> result, got {type(result)}"
assert isinstance(result, str), (
f"Expected string as <REGION_TO_CATEGORY> result, got {type(result)}"
)

if result == "No object detected.":
return np.empty((0, 4), dtype=np.float32), np.array([]), None, None

pattern = re.compile(r"<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>")
match = pattern.search(result)
assert (
match is not None
), f"Expected string to end in location tags, but got {result}"
assert match is not None, (
f"Expected string to end in location tags, but got {result}"
)

w, h = resolution_wh
xyxy = np.array([match.groups()], dtype=np.float32)
Expand Down
3 changes: 1 addition & 2 deletions supervision/detection/overlap_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ def box_non_max_merge(
for merge_group in merge_groups:
if len(merge_group) == 0:
raise ValueError(
f"Empty group detected when non-max-merging "
f"detections: {merge_groups}"
f"Empty group detected when non-max-merging detections: {merge_groups}"
)
return merge_groups

Expand Down
3 changes: 1 addition & 2 deletions supervision/metrics/mean_average_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,7 @@ def plot(self):
ax.set_ylim(0, 1)
ax.set_ylabel("Value", fontweight="bold")
title = (
f"Mean Average Recall, by Object Size"
f"\n(target: {self.metric_target.value})"
f"Mean Average Recall, by Object Size\n(target: {self.metric_target.value})"
)
ax.set_title(title, fontweight="bold")

Expand Down
2 changes: 1 addition & 1 deletion supervision/validators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def validate_confidence(confidence: Any, n: int) -> None:


def validate_keypoint_confidence(confidence: Any, n: int, m: int) -> None:
expected_shape = f"({n,m})"
expected_shape = f"({n, m})"
actual_shape = str(getattr(confidence, "shape", None))

if confidence is not None:
Expand Down
6 changes: 3 additions & 3 deletions test/detection/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ def assert_csv_equal(file_name, expected_rows):
with open(file_name, mode="r", newline="") as file:
reader = csv.reader(file)
for i, row in enumerate(reader):
assert (
[str(item) for item in expected_rows[i]] == row
), f"Row in CSV didn't match expected output: {row} != {expected_rows[i]}"
assert [str(item) for item in expected_rows[i]] == row, (
f"Row in CSV didn't match expected output: {row} != {expected_rows[i]}"
)

os.remove(file_name)
6 changes: 3 additions & 3 deletions test/detection/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ def test_json_sink(
def assert_json_equal(file_name, expected_rows):
with open(file_name, "r") as file:
data = json.load(file)
assert (
data == expected_rows
), f"Data in JSON file didn't match expected output: {data} != {expected_rows}"
assert data == expected_rows, (
f"Data in JSON file didn't match expected output: {data} != {expected_rows}"
)

os.remove(file_name)
36 changes: 18 additions & 18 deletions test/detection/test_line_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ def test_line_zone_one_detection_default_anchors(
crossed_in_list.append(crossed_in[0])
crossed_out_list.append(crossed_out[0])

assert (
crossed_in_list == expected_crossed_in
), f"expected {expected_crossed_in}, got {crossed_in_list}"
assert (
crossed_out_list == expected_crossed_out
), f"expected {expected_crossed_out}, got {crossed_out_list}"
assert crossed_in_list == expected_crossed_in, (
f"expected {expected_crossed_in}, got {crossed_in_list}"
)
assert crossed_out_list == expected_crossed_out, (
f"expected {expected_crossed_out}, got {crossed_out_list}"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -415,12 +415,12 @@ def test_line_zone_one_detection(
crossed_in_list.append(crossed_in[0])
crossed_out_list.append(crossed_out[0])

assert (
crossed_in_list == expected_crossed_in
), f"expected {expected_crossed_in}, got {crossed_in_list}"
assert (
crossed_out_list == expected_crossed_out
), f"expected {expected_crossed_out}, got {crossed_out_list}"
assert crossed_in_list == expected_crossed_in, (
f"expected {expected_crossed_in}, got {crossed_in_list}"
)
assert crossed_out_list == expected_crossed_out, (
f"expected {expected_crossed_out}, got {crossed_out_list}"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -600,12 +600,12 @@ def test_line_zone_one_detection_long_horizon(
crossed_in_list.append(crossed_in[0])
crossed_out_list.append(crossed_out[0])

assert (
crossed_in_list == expected_crossed_in
), f"expected {expected_crossed_in}, got {crossed_in_list}"
assert (
crossed_out_list == expected_crossed_out
), f"expected {expected_crossed_out}, got {crossed_out_list}"
assert crossed_in_list == expected_crossed_in, (
f"expected {expected_crossed_in}, got {crossed_in_list}"
)
assert crossed_out_list == expected_crossed_out, (
f"expected {expected_crossed_out}, got {crossed_out_list}"
)


@pytest.mark.parametrize(
Expand Down
36 changes: 18 additions & 18 deletions test/detection/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,13 @@ def test_process_roboflow_result(
)
for key in result[5]:
if isinstance(result[5][key], np.ndarray):
assert np.array_equal(
result[5][key], expected_result[5][key]
), f"Mismatch in arrays for key {key}"
assert np.array_equal(result[5][key], expected_result[5][key]), (
f"Mismatch in arrays for key {key}"
)
else:
assert (
result[5][key] == expected_result[5][key]
), f"Mismatch in non-array data for key {key}"
assert result[5][key] == expected_result[5][key], (
f"Mismatch in non-array data for key {key}"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1041,13 +1041,13 @@ def test_merge_data(

for key in result:
if isinstance(result[key], np.ndarray):
assert np.array_equal(
result[key], expected_result[key]
), f"Mismatch in arrays for key {key}"
assert np.array_equal(result[key], expected_result[key]), (
f"Mismatch in arrays for key {key}"
)
else:
assert (
result[key] == expected_result[key]
), f"Mismatch in non-array data for key {key}"
assert result[key] == expected_result[key], (
f"Mismatch in non-array data for key {key}"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1214,13 +1214,13 @@ def test_get_data_item(
result = get_data_item(data=data, index=index)
for key in result:
if isinstance(result[key], np.ndarray):
assert np.array_equal(
result[key], expected_result[key]
), f"Mismatch in arrays for key {key}"
assert np.array_equal(result[key], expected_result[key]), (
f"Mismatch in arrays for key {key}"
)
else:
assert (
result[key] == expected_result[key]
), f"Mismatch in non-array data for key {key}"
assert result[key] == expected_result[key], (
f"Mismatch in non-array data for key {key}"
)


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions test/detection/tools/test_inference_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,6 @@ def test_generate_offset(
)

# Verify that the generated offsets match the expected offsets
assert np.array_equal(
offsets, expected_offsets
), f"Expected {expected_offsets}, got {offsets}"
assert np.array_equal(offsets, expected_offsets), (
f"Expected {expected_offsets}, got {offsets}"
)
72 changes: 36 additions & 36 deletions test/utils/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def my_custom_processing_function(
param_a: int,
param_b: str,
) -> np.ndarray:
assert np.allclose(
image, empty_cv2_image
), "Expected conversion to OpenCV image to happen"
assert (
param_a == param_a_value
), f"Parameter a expected to be {param_a_value} in target function"
assert (
param_b == param_b_value
), f"Parameter b expected to be {param_b_value} in target function"
assert np.allclose(image, empty_cv2_image), (
"Expected conversion to OpenCV image to happen"
)
assert param_a == param_a_value, (
f"Parameter a expected to be {param_a_value} in target function"
)
assert param_b == param_b_value, (
f"Parameter b expected to be {param_b_value} in target function"
)
return image

# when
Expand Down Expand Up @@ -61,15 +61,15 @@ def my_custom_processing_function(
param_a: int,
param_b: str,
) -> np.ndarray:
assert np.allclose(
image, empty_cv2_image
), "Expected conversion to OpenCV image to happen"
assert (
param_a == param_a_value
), f"Parameter a expected to be {param_a_value} in target function"
assert (
param_b == param_b_value
), f"Parameter b expected to be {param_b_value} in target function"
assert np.allclose(image, empty_cv2_image), (
"Expected conversion to OpenCV image to happen"
)
assert param_a == param_a_value, (
f"Parameter a expected to be {param_a_value} in target function"
)
assert param_b == param_b_value, (
f"Parameter b expected to be {param_b_value} in target function"
)
return image

# when
Expand All @@ -91,9 +91,9 @@ def test_cv2_to_pillow(

# then
difference = ImageChops.difference(result, empty_pillow_image)
assert (
difference.getbbox() is None
), "Conversion to PIL.Image expected not to change the content of image"
assert difference.getbbox() is None, (
"Conversion to PIL.Image expected not to change the content of image"
)


def test_pillow_to_cv2(
Expand All @@ -103,9 +103,9 @@ def test_pillow_to_cv2(
result = pillow_to_cv2(image=empty_pillow_image)

# then
assert np.allclose(
result, empty_cv2_image
), "Conversion to OpenCV image expected not to change the content of image"
assert np.allclose(result, empty_cv2_image), (
"Conversion to OpenCV image expected not to change the content of image"
)


def test_images_to_cv2_when_empty_input_provided() -> None:
Expand All @@ -128,9 +128,9 @@ def test_images_to_cv2_when_only_cv2_images_provided(
# then
assert len(result) == 5, "Expected the same number of output element as input ones"
for result_element in result:
assert (
result_element is empty_cv2_image
), "Expected CV images not to be touched by conversion"
assert result_element is empty_cv2_image, (
"Expected CV images not to be touched by conversion"
)


def test_images_to_cv2_when_only_pillow_images_provided(
Expand All @@ -146,9 +146,9 @@ def test_images_to_cv2_when_only_pillow_images_provided(
# then
assert len(result) == 5, "Expected the same number of output element as input ones"
for result_element in result:
assert np.allclose(
result_element, empty_cv2_image
), "Output images expected to be equal to empty OpenCV image"
assert np.allclose(result_element, empty_cv2_image), (
"Output images expected to be equal to empty OpenCV image"
)


def test_images_to_cv2_when_mixed_input_provided(
Expand All @@ -163,9 +163,9 @@ def test_images_to_cv2_when_mixed_input_provided(

# then
assert len(result) == 2, "Expected the same number of output element as input ones"
assert np.allclose(
result[0], empty_cv2_image
), "PIL image should be converted to OpenCV one, equal to example empty image"
assert (
result[1] is empty_cv2_image
), "Expected CV images not to be touched by conversion"
assert np.allclose(result[0], empty_cv2_image), (
"PIL image should be converted to OpenCV one, equal to example empty image"
)
assert result[1] is empty_cv2_image, (
"Expected CV images not to be touched by conversion"
)
Loading
Loading