fix #386: ensure generate_scope_key always returns a hashable string key#435
Draft
cursor[bot] wants to merge 1 commit intomainfrom
Draft
fix #386: ensure generate_scope_key always returns a hashable string key#435cursor[bot] wants to merge 1 commit intomainfrom
cursor[bot] wants to merge 1 commit intomainfrom
Conversation
The except fallback in generate_scope_key could leave scope_key as a raw list/tuple/ndarray when get_data_list raised an exception. This unhashable value would then be used as a dict key in ScopesData.__setitem__, causing TypeError: unhashable type: 'list'. Fix: in the except block, convert list/tuple/ndarray scopes to a proper scope_[...] string, and fall back to str(scope) for any other type. Also adds a standalone test suite for generate_scope_key covering all scope types including the regression case. Co-authored-by: wanruiwen-genomics-cn <wanruiwen-genomics-cn@users.noreply.github.com>
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.
Summary
The
generate_scope_keymethod instereo/core/ms_data.pyhas a bareexceptfallback that setsscope_key = scope. Whenscopeis a list (e.g., when called withms_data_view._names), this produces an unhashable list that cannot be used as a dictionary key. The list is subsequently passed toScopesData.__setitem__, which inherits fromdict, causingTypeError: unhashable type: 'list'.Changes
stereo/core/ms_data.py: Updated theexceptblock ingenerate_scope_keyto always produce a hashable string key:scope_[x,y,z]format stringself._names[scope]to resolve namesstr(scope)except:toexcept Exception:(best practice)tests/test_generate_scope_key.py: Added 11 unit tests covering all scope types, including the regression case with unknown names that triggered the original bugVerification
Classification
Closes #386