From 1c3a0007adb7cffa000ca4a2d29b7ed7ea5d8a2e Mon Sep 17 00:00:00 2001 From: Vidhu Arora Date: Fri, 31 Jul 2026 16:07:55 +0530 Subject: [PATCH 1/2] fix(sorts): raise ValueError for negative inputs in radix_sort (#14950) --- sorts/radix_sort.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 1dbf5fbd1365..47c5dd8720e3 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -21,7 +21,17 @@ def radix_sort(list_of_ints: list[int]) -> list[int]: True >>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000]) True + >>> radix_sort([-1, 2, 3]) + Traceback (most recent call last): + ... + ValueError: All elements in list_of_ints must be non-negative integers """ + if not list_of_ints: + return [] + + if any(i < 0 for i in list_of_ints): + raise ValueError("All elements in list_of_ints must be non-negative integers") + placement = 1 max_digit = max(list_of_ints) while placement <= max_digit: From 51241b15e1c785c0f5be9b1e9eecff83b046a5a2 Mon Sep 17 00:00:00 2001 From: Vidhu Arora Date: Fri, 31 Jul 2026 16:09:05 +0530 Subject: [PATCH 2/2] fix(sorts): raise TypeError when bucket_count is not an integer in bucket_sort (#14970) --- sorts/bucket_sort.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index 893c7ff3a23a..1801e20ad315 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -71,7 +71,13 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: >>> data = [9, 2, 7, 1, 5] >>> bucket_sort(data) == sorted(data) True + >>> bucket_sort([1, 2, 3], bucket_count=2.5) + Traceback (most recent call last): + ... + TypeError: bucket_count must be an integer """ + if not isinstance(bucket_count, int) or isinstance(bucket_count, bool): + raise TypeError("bucket_count must be an integer") if len(my_list) == 0 or bucket_count <= 0: return []