Skip to content

fix #386: ensure generate_scope_key always returns a hashable string key#435

Draft
cursor[bot] wants to merge 1 commit intomainfrom
cursorautomated-issue-handler-192c
Draft

fix #386: ensure generate_scope_key always returns a hashable string key#435
cursor[bot] wants to merge 1 commit intomainfrom
cursorautomated-issue-handler-192c

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor bot commented Mar 30, 2026

Summary

The generate_scope_key method in stereo/core/ms_data.py has a bare except fallback that sets scope_key = scope. When scope is a list (e.g., when called with ms_data_view._names), this produces an unhashable list that cannot be used as a dictionary key. The list is subsequently passed to ScopesData.__setitem__, which inherits from dict, causing TypeError: unhashable type: 'list'.

Changes

  • stereo/core/ms_data.py: Updated the except block in generate_scope_key to always produce a hashable string key:
    • For list/tuple/ndarray/Index scopes: generates scope_[x,y,z] format string
    • For slice scopes: uses self._names[scope] to resolve names
    • For any other type: falls back to str(scope)
    • Changed bare except: to except 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 bug

Verification

  • AST syntax check passed
  • Import check passed (via AST extraction for isolated testing)
  • All 11 unit tests pass

Classification

  • Type: bug
  • Confidence: high
  • Severity: high

Closes #386

Open in Web View Automation 

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error in ms_data.tl.cal_qc(scope=slice_generator[:],mode='integrate')

1 participant