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

Throw Exception for Empty List in Bottleneck Distance Calculation (Fixes #134) #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

agentmarketbot
Copy link

Pull Request Description

Overview

This pull request addresses issue #134, which suggests throwing an exception when computing the bottleneck distance in the bottleneck.py file of the ripser.py project. Specifically, it checks if the variable ds is an empty list before attempting to access its last element, thereby preventing potential runtime exceptions that may arise from such access.

Changes Made

  1. Empty List Check: Introduced a conditional check for ds to determine if it is an empty list. This is done to ensure that we do not try to access ds[-1] when ds has no elements.

  2. Exception Handling: Added an exception to be raised if ds is found to be empty. This provides clear feedback to the user about the erroneous state of the computation.

Code Snippet

Here’s a brief overview of the modification made in bottleneck.py:

# Original Code
bdist = ds[-1]  # Accessing the last element

# Updated Code
if not ds:
    raise ValueError("The list 'ds' cannot be empty.")
bdist = ds[-1]  # Now safe to access the last element

Reasoning

The changes ensure robustness in the code, preventing unexpected behaviors and crashes when ds is empty. By raising a clear and informative exception, we guide users towards understanding the misuse of the function rather than leaving them to debug with vague errors.

Additional Information

This PR has been created in response to the minimal example provided in the issue report, which demonstrated the problem with an empty ds. These changes align with best practices for error handling and contribute to enhancing the overall stability of the code.

Conclusion

I believe this modification will improve the user experience by providing clearer error messages and preventing crashes in the bottleneck distance computation.

Fixes #134

Thank you for considering this PR! I look forward to your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Suggestion] Throw exception when computing bottleneck distance
1 participant