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

BUG: Subtle bug in merge_sort with length 1 lists (note complication) #14

Open
seberg opened this issue Aug 20, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@seberg
Copy link
Collaborator

seberg commented Aug 20, 2024

When sorting a length 1 list, the returned list is identical to the input list. This leads to a subtle inconsistency and a copy should be returned.

As a toy example, if the code for example, replaces the largest element later:

data = [1, 2]  # or [1]

sorted_data = merge_sort(data)
sorted_data[-1] = 999

then the original data is normally not be modified. But if the input has length 1, it will be.

Minimal reproducer

from listwiz.sorting import merge_sort 

in1 = [1]

res1 = merge_sort(in1)

assert res1 is not in1  # assertion should not fail

Working on the issue

When fixing this issue, make sure to add a new test function (after test_mergesort_empty!).

NOTE: If you work on this issue, changes are likely to conflict with the issue gh-8. This means that whichever PR is merged second, will need to deal with the "merge conflict".
Because of that and we may wait with merging this until the other PR is merged.

@seberg seberg added the bug Something isn't working label Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant