Fix: Correct variable reference in flatten() function#44751
Closed
LincolnBurrows2017 wants to merge 3 commits intohuggingface:mainfrom
Closed
Fix: Correct variable reference in flatten() function#44751LincolnBurrows2017 wants to merge 3 commits intohuggingface:mainfrom
LincolnBurrows2017 wants to merge 3 commits intohuggingface:mainfrom
Conversation
- Fixed is_batched() to handle empty lists without IndexError - Fixed make_flat_list_of_images() to handle empty lists - Fixed make_nested_list_of_images() to handle empty lists - Fixed concatenate_list() to handle empty lists - Added tests for all these cases These functions were accessing list[0] without checking if the list was empty, causing IndexError exceptions when empty lists were passed.
The flatten() function was incorrectly checking arr[0] instead of sub_arr when determining if an element should be recursively flattened. This caused a TypeError when processing mixed lists like [[1,2], 3, [4,5]] where non-list elements followed list elements. Changed isinstance(arr[0], (list, tuple)) to isinstance(sub_arr, (list, tuple)) to correctly check each element during iteration.
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: doge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR fix?
The
flatten()function intokenization_utils_base.pyhad a bug where it was checkingarr[0]instead ofsub_arrwhen determining if an element should be recursively flattened.Bug Details
src/transformers/tokenization_utils_base.pyflatten()isinstance(arr[0], (list, tuple))should beisinstance(sub_arr, (list, tuple))Impact
This bug caused a
TypeError: object of type int has no len()when processing mixed lists like[[1,2], 3, [4,5]]where non-list elements followed list elements.Example