fix: handle all test_range types in SizePartitioner.get_cost#2438
Open
octo-patch wants to merge 1 commit intoopen-compass:mainfrom
Open
fix: handle all test_range types in SizePartitioner.get_cost#2438octo-patch wants to merge 1 commit intoopen-compass:mainfrom
octo-patch wants to merge 1 commit intoopen-compass:mainfrom
Conversation
…pen-compass#2430) The previous implementation used an eval trick that only worked for string test_range values (e.g. "[:100]"). Passing an int, float, or None caused a SyntaxError because the expression became invalid Python. Introduce _get_actual_size() that mirrors the slicing logic already used in load_partial_dataset(), handling None/empty-string, int, float (<1 as ratio, >=1 as count), and string slice notation correctly.
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.
Fixes #2430
Problem
SizePartitioner.get_cost()computedactual_sizeusing anevaltrick:This constructs expressions like
len(range(N)[:100])and relies ontest_rangebeing a string slice. However,test_rangecan also beNone, anint, or afloat(all documented inDatasetReader), which causes aSyntaxError:None→len(range(N))None)— syntax errorint 100→len(range(N))100)— syntax errorfloat 0.5→len(range(N))0.5)— syntax errorSolution
Add
_get_actual_size(test_range, total_size)that mirrors the branching logic already present inload_partial_dataset()(inicl_dataset_reader.py) without loading the dataset into memory:test_rangetypeNone/ empty stringint/floatoutside(0, total_size)floatin(0, 1)int(test_range * total_size)intin(0, total_size)int(test_range)str(e.g."[:100]")len(index_list{test_range})Both
evalcall-sites inget_cost()are replaced with calls to this helper.Testing
Manually verified with representative inputs: