Throw Exception for Empty List in Bottleneck Distance Calculation (Fixes #134) #184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 variableds
is an empty list before attempting to access its last element, thereby preventing potential runtime exceptions that may arise from such access.Changes Made
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 accessds[-1]
whends
has no elements.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
: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.