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

midsize_file Function Does Not Return Median File #611

Closed
michaelsykes opened this issue May 3, 2021 · 1 comment · Fixed by #613
Closed

midsize_file Function Does Not Return Median File #611

michaelsykes opened this issue May 3, 2021 · 1 comment · Fixed by #613
Labels

Comments

@michaelsykes
Copy link

michaelsykes commented May 3, 2021

From autobin.py:

def midsize_file(fnames):
    """Select the median-size file from several given filenames.

    If an even number of files is given, selects the file just below the median.
    """
    return sorted(fnames, key=lambda f: os.stat(f).st_size
                 )[len(fnames) // 2 - 1]
  • Consider 8 files. The median should be the 4th file in this case (median is between 4/5), or list index 3. This is correctly calculated
8 // 2 = 4
4 - 1 = 3
  • Consider 7 files. The median should be the 4th file, or list index 3. This is incorrectly calculated as index 2, the value just below the median
7 // 2 = 3
3 - 1 = 2
tskir added a commit that referenced this issue May 9, 2021
@tskir tskir added the bug label May 9, 2021
@tskir
Copy link
Collaborator

tskir commented May 9, 2021

@michaelsykes Thank you very much for noticing this! I've submitted a PR to fix the issue

@etal etal closed this as completed in #613 May 24, 2021
etal pushed a commit that referenced this issue May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants