Skip to content

bucket_sort has no dedicated error handling when the number of buckets in inputted as a float instead of an integer. #14970

Description

@ThayerMarvin

Feature description

Issue:

The bucket_sort function accepts an integer passed as an argument

def bucket_sort(my_list: list, bucket_count: int = 10)

When passing a float it causes an unhandled TypeError

Test used:

>>> data = [12, 7 , 22, 11, 4]
>>> bucket_sort(data, 2.5) == sorted(data)
True

TypeError: 'float' object cannot be interpreted as an integer

Proposed solution:

Either return an empty list for consistency to match when a bucket count of less than 0 is used

if len(my_list) == 0 or bucket_count <= 0 or not isinstance(bucket_count, int):
return [ ]

Or raise a clearer TypeError

if not isinstance(bucket_count, int):
raise TypeError("bucket_count must be an integer")

I would like to implement either solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis PR modified some existing files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions