Skip to content

Commit f6dc79d

Browse files
fix(pre_commit): 🎨 auto format pre-commit hooks
1 parent af02d61 commit f6dc79d

File tree

12 files changed

+106
-108
lines changed

12 files changed

+106
-108
lines changed

‎supervision/detection/core.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def from_azure_analyze_image(
712712
"""
713713
if "error" in azure_result:
714714
raise ValueError(
715-
f'Azure API returned an error {azure_result["error"]["message"]}'
715+
f"Azure API returned an error {azure_result['error']['message']}"
716716
)
717717

718718
xyxy, confidences, class_ids = [], [], []
@@ -1306,9 +1306,9 @@ def with_nms(
13061306
if len(self) == 0:
13071307
return self
13081308

1309-
assert (
1310-
self.confidence is not None
1311-
), "Detections confidence must be given for NMS to be executed."
1309+
assert self.confidence is not None, (
1310+
"Detections confidence must be given for NMS to be executed."
1311+
)
13121312

13131313
if class_agnostic:
13141314
predictions = np.hstack((self.xyxy, self.confidence.reshape(-1, 1)))
@@ -1362,9 +1362,9 @@ def with_nmm(
13621362
if len(self) == 0:
13631363
return self
13641364

1365-
assert (
1366-
self.confidence is not None
1367-
), "Detections confidence must be given for NMM to be executed."
1365+
assert self.confidence is not None, (
1366+
"Detections confidence must be given for NMM to be executed."
1367+
)
13681368

13691369
if class_agnostic:
13701370
predictions = np.hstack((self.xyxy, self.confidence.reshape(-1, 1)))

‎supervision/detection/lmm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,18 @@ def from_florence_2(
161161
return xyxy, labels, None, None
162162

163163
if task in ["<REGION_TO_CATEGORY>", "<REGION_TO_DESCRIPTION>"]:
164-
assert isinstance(
165-
result, str
166-
), f"Expected string as <REGION_TO_CATEGORY> result, got {type(result)}"
164+
assert isinstance(result, str), (
165+
f"Expected string as <REGION_TO_CATEGORY> result, got {type(result)}"
166+
)
167167

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

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

177177
w, h = resolution_wh
178178
xyxy = np.array([match.groups()], dtype=np.float32)

‎supervision/detection/overlap_filter.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ def box_non_max_merge(
226226
for merge_group in merge_groups:
227227
if len(merge_group) == 0:
228228
raise ValueError(
229-
f"Empty group detected when non-max-merging "
230-
f"detections: {merge_groups}"
229+
f"Empty group detected when non-max-merging detections: {merge_groups}"
231230
)
232231
return merge_groups
233232

‎supervision/metrics/mean_average_recall.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,7 @@ def plot(self):
670670
ax.set_ylim(0, 1)
671671
ax.set_ylabel("Value", fontweight="bold")
672672
title = (
673-
f"Mean Average Recall, by Object Size"
674-
f"\n(target: {self.metric_target.value})"
673+
f"Mean Average Recall, by Object Size\n(target: {self.metric_target.value})"
675674
)
676675
ax.set_title(title, fontweight="bold")
677676

‎supervision/validators/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def validate_confidence(confidence: Any, n: int) -> None:
5454

5555

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

6060
if confidence is not None:

‎test/detection/test_csv.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ def assert_csv_equal(file_name, expected_rows):
408408
with open(file_name, mode="r", newline="") as file:
409409
reader = csv.reader(file)
410410
for i, row in enumerate(reader):
411-
assert (
412-
[str(item) for item in expected_rows[i]] == row
413-
), f"Row in CSV didn't match expected output: {row} != {expected_rows[i]}"
411+
assert [str(item) for item in expected_rows[i]] == row, (
412+
f"Row in CSV didn't match expected output: {row} != {expected_rows[i]}"
413+
)
414414

415415
os.remove(file_name)

‎test/detection/test_json.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ def test_json_sink(
242242
def assert_json_equal(file_name, expected_rows):
243243
with open(file_name, "r") as file:
244244
data = json.load(file)
245-
assert (
246-
data == expected_rows
247-
), f"Data in JSON file didn't match expected output: {data} != {expected_rows}"
245+
assert data == expected_rows, (
246+
f"Data in JSON file didn't match expected output: {data} != {expected_rows}"
247+
)
248248

249249
os.remove(file_name)

‎test/detection/test_line_counter.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,12 @@ def test_line_zone_one_detection_default_anchors(
250250
crossed_in_list.append(crossed_in[0])
251251
crossed_out_list.append(crossed_out[0])
252252

253-
assert (
254-
crossed_in_list == expected_crossed_in
255-
), f"expected {expected_crossed_in}, got {crossed_in_list}"
256-
assert (
257-
crossed_out_list == expected_crossed_out
258-
), f"expected {expected_crossed_out}, got {crossed_out_list}"
253+
assert crossed_in_list == expected_crossed_in, (
254+
f"expected {expected_crossed_in}, got {crossed_in_list}"
255+
)
256+
assert crossed_out_list == expected_crossed_out, (
257+
f"expected {expected_crossed_out}, got {crossed_out_list}"
258+
)
259259

260260

261261
@pytest.mark.parametrize(
@@ -415,12 +415,12 @@ def test_line_zone_one_detection(
415415
crossed_in_list.append(crossed_in[0])
416416
crossed_out_list.append(crossed_out[0])
417417

418-
assert (
419-
crossed_in_list == expected_crossed_in
420-
), f"expected {expected_crossed_in}, got {crossed_in_list}"
421-
assert (
422-
crossed_out_list == expected_crossed_out
423-
), f"expected {expected_crossed_out}, got {crossed_out_list}"
418+
assert crossed_in_list == expected_crossed_in, (
419+
f"expected {expected_crossed_in}, got {crossed_in_list}"
420+
)
421+
assert crossed_out_list == expected_crossed_out, (
422+
f"expected {expected_crossed_out}, got {crossed_out_list}"
423+
)
424424

425425

426426
@pytest.mark.parametrize(
@@ -600,12 +600,12 @@ def test_line_zone_one_detection_long_horizon(
600600
crossed_in_list.append(crossed_in[0])
601601
crossed_out_list.append(crossed_out[0])
602602

603-
assert (
604-
crossed_in_list == expected_crossed_in
605-
), f"expected {expected_crossed_in}, got {crossed_in_list}"
606-
assert (
607-
crossed_out_list == expected_crossed_out
608-
), f"expected {expected_crossed_out}, got {crossed_out_list}"
603+
assert crossed_in_list == expected_crossed_in, (
604+
f"expected {expected_crossed_in}, got {crossed_in_list}"
605+
)
606+
assert crossed_out_list == expected_crossed_out, (
607+
f"expected {expected_crossed_out}, got {crossed_out_list}"
608+
)
609609

610610

611611
@pytest.mark.parametrize(

‎test/detection/test_utils.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,13 @@ def test_process_roboflow_result(
388388
)
389389
for key in result[5]:
390390
if isinstance(result[5][key], np.ndarray):
391-
assert np.array_equal(
392-
result[5][key], expected_result[5][key]
393-
), f"Mismatch in arrays for key {key}"
391+
assert np.array_equal(result[5][key], expected_result[5][key]), (
392+
f"Mismatch in arrays for key {key}"
393+
)
394394
else:
395-
assert (
396-
result[5][key] == expected_result[5][key]
397-
), f"Mismatch in non-array data for key {key}"
395+
assert result[5][key] == expected_result[5][key], (
396+
f"Mismatch in non-array data for key {key}"
397+
)
398398

399399

400400
@pytest.mark.parametrize(
@@ -1041,13 +1041,13 @@ def test_merge_data(
10411041

10421042
for key in result:
10431043
if isinstance(result[key], np.ndarray):
1044-
assert np.array_equal(
1045-
result[key], expected_result[key]
1046-
), f"Mismatch in arrays for key {key}"
1044+
assert np.array_equal(result[key], expected_result[key]), (
1045+
f"Mismatch in arrays for key {key}"
1046+
)
10471047
else:
1048-
assert (
1049-
result[key] == expected_result[key]
1050-
), f"Mismatch in non-array data for key {key}"
1048+
assert result[key] == expected_result[key], (
1049+
f"Mismatch in non-array data for key {key}"
1050+
)
10511051

10521052

10531053
@pytest.mark.parametrize(
@@ -1214,13 +1214,13 @@ def test_get_data_item(
12141214
result = get_data_item(data=data, index=index)
12151215
for key in result:
12161216
if isinstance(result[key], np.ndarray):
1217-
assert np.array_equal(
1218-
result[key], expected_result[key]
1219-
), f"Mismatch in arrays for key {key}"
1217+
assert np.array_equal(result[key], expected_result[key]), (
1218+
f"Mismatch in arrays for key {key}"
1219+
)
12201220
else:
1221-
assert (
1222-
result[key] == expected_result[key]
1223-
), f"Mismatch in non-array data for key {key}"
1221+
assert result[key] == expected_result[key], (
1222+
f"Mismatch in non-array data for key {key}"
1223+
)
12241224

12251225

12261226
@pytest.mark.parametrize(

‎test/detection/tools/test_inference_slicer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,6 @@ def test_generate_offset(
180180
)
181181

182182
# Verify that the generated offsets match the expected offsets
183-
assert np.array_equal(
184-
offsets, expected_offsets
185-
), f"Expected {expected_offsets}, got {offsets}"
183+
assert np.array_equal(offsets, expected_offsets), (
184+
f"Expected {expected_offsets}, got {offsets}"
185+
)

‎test/utils/test_conversion.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ def my_custom_processing_function(
2222
param_a: int,
2323
param_b: str,
2424
) -> np.ndarray:
25-
assert np.allclose(
26-
image, empty_cv2_image
27-
), "Expected conversion to OpenCV image to happen"
28-
assert (
29-
param_a == param_a_value
30-
), f"Parameter a expected to be {param_a_value} in target function"
31-
assert (
32-
param_b == param_b_value
33-
), f"Parameter b expected to be {param_b_value} in target function"
25+
assert np.allclose(image, empty_cv2_image), (
26+
"Expected conversion to OpenCV image to happen"
27+
)
28+
assert param_a == param_a_value, (
29+
f"Parameter a expected to be {param_a_value} in target function"
30+
)
31+
assert param_b == param_b_value, (
32+
f"Parameter b expected to be {param_b_value} in target function"
33+
)
3434
return image
3535

3636
# when
@@ -61,15 +61,15 @@ def my_custom_processing_function(
6161
param_a: int,
6262
param_b: str,
6363
) -> np.ndarray:
64-
assert np.allclose(
65-
image, empty_cv2_image
66-
), "Expected conversion to OpenCV image to happen"
67-
assert (
68-
param_a == param_a_value
69-
), f"Parameter a expected to be {param_a_value} in target function"
70-
assert (
71-
param_b == param_b_value
72-
), f"Parameter b expected to be {param_b_value} in target function"
64+
assert np.allclose(image, empty_cv2_image), (
65+
"Expected conversion to OpenCV image to happen"
66+
)
67+
assert param_a == param_a_value, (
68+
f"Parameter a expected to be {param_a_value} in target function"
69+
)
70+
assert param_b == param_b_value, (
71+
f"Parameter b expected to be {param_b_value} in target function"
72+
)
7373
return image
7474

7575
# when
@@ -91,9 +91,9 @@ def test_cv2_to_pillow(
9191

9292
# then
9393
difference = ImageChops.difference(result, empty_pillow_image)
94-
assert (
95-
difference.getbbox() is None
96-
), "Conversion to PIL.Image expected not to change the content of image"
94+
assert difference.getbbox() is None, (
95+
"Conversion to PIL.Image expected not to change the content of image"
96+
)
9797

9898

9999
def test_pillow_to_cv2(
@@ -103,9 +103,9 @@ def test_pillow_to_cv2(
103103
result = pillow_to_cv2(image=empty_pillow_image)
104104

105105
# then
106-
assert np.allclose(
107-
result, empty_cv2_image
108-
), "Conversion to OpenCV image expected not to change the content of image"
106+
assert np.allclose(result, empty_cv2_image), (
107+
"Conversion to OpenCV image expected not to change the content of image"
108+
)
109109

110110

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

135135

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

153153

154154
def test_images_to_cv2_when_mixed_input_provided(
@@ -163,9 +163,9 @@ def test_images_to_cv2_when_mixed_input_provided(
163163

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

‎test/utils/test_image.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def test_resize_image_for_opencv_image() -> None:
2121
)
2222

2323
# then
24-
assert np.allclose(
25-
result, expected_result
26-
), "Expected output shape to be (w, h): (1024, 768)"
24+
assert np.allclose(result, expected_result), (
25+
"Expected output shape to be (w, h): (1024, 768)"
26+
)
2727

2828

2929
def test_resize_image_for_pillow_image() -> None:
@@ -41,9 +41,9 @@ def test_resize_image_for_pillow_image() -> None:
4141
# then
4242
assert result.size == (1024, 768), "Expected output shape to be (w, h): (1024, 768)"
4343
difference = ImageChops.difference(result, expected_result)
44-
assert (
45-
difference.getbbox() is None
46-
), "Expected no difference in resized image content as the image is all zeros"
44+
assert difference.getbbox() is None, (
45+
"Expected no difference in resized image content as the image is all zeros"
46+
)
4747

4848

4949
def test_letterbox_image_for_opencv_image() -> None:
@@ -95,9 +95,9 @@ def test_letterbox_image_for_pillow_image() -> None:
9595
1024,
9696
), "Expected output shape to be (w, h): (1024, 1024)"
9797
difference = ImageChops.difference(result, expected_result)
98-
assert (
99-
difference.getbbox() is None
100-
), "Expected padding to be added top and bottom with padding added top and bottom"
98+
assert difference.getbbox() is None, (
99+
"Expected padding to be added top and bottom with padding added top and bottom"
100+
)
101101

102102

103103
def test_create_tiles_with_one_image(

0 commit comments

Comments
 (0)