[REF] Compute_plausible_gaps, Efficiency, Stability #243
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.
Use of
get
Method: When retrieving the best alignment, we useself._textline_to_alignments.get(most_aligned_tl)
instead of direct indexing. This prevents a potentialKeyError
ifmost_aligned_tl
is not in the dictionary, which could lead to unexpected behavior.Early Exit Conditions: We explicitly check if
best_alignment
isNone
after attempting to retrieve it. This ensures that we do not proceed with calculations if the alignment data is missing.Sorting and Gap Calculation: I retained the logic to sort the text lines and calculate gaps. This part of the code is straightforward and unlikely to lead to an infinite loop as long as the input lists are correctly managed.
Returning
None
for Insufficient Data: The checks for the lengths of the text line lists ensure that we only proceed if there are enough lines to compute meaningful gaps. If there are not enough lines, we returnNone
to avoid further computation.List Comprehensions for Gap Calculation: The gap calculations for horizontal and vertical gaps are done using list comprehensions, which are more concise and Pythonic, making the code cleaner.