Skip to content

Conversation

@xbyrne
Copy link

@xbyrne xbyrne commented Oct 29, 2025

❗ Problem

This PR fixes an issue where locals() was used inside a list comprehension (in modeling.ssf.model_spectrum, where the script checks that all input variables have the same number of elements).

This issue was throwing KeyErrors whenever the model_spectrum function was called, as list comprehensions have their own local scope (see this Stack Overflow post) so it couldn't find any variables defined outside the comprehension.

🔧 Fix

The fix is very simple -- take a snapshot of the local variables before executing the list comprehension:

-    lengths = {name: len(locals()[name]) for name in names}

+    local_snapshot = dict(locals())
+    lengths = {name: len(local_snapshot[name]) for name in names}

With this change, the model_spectrum function runs fine. There are no necessary API changes or changes to other parts of the codebase.

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.

1 participant