Skip to content

[FIX] create a SignalObj from any calling function - #59

Open
aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-fix_instanceinfo
Open

aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-fix_instanceinfo

Conversation

@aguirreSL

@aguirreSL aguirreSL commented Oct 31, 2026 •

Copy link
Copy Markdown

Creating a SignalObj inside a function failed in two common cases:

def make(data):                 # first local variable is an array
    return pytta.SignalObj(data, 'time', 48000)
# ValueError: The truth value of an array with more than one element is ambiguous.

def load():
    sig = pytta.SignalObj(np.ones(8), 'time', 48000)   # `sig` not set yet
# KeyError: 'sig'

RememberInstanceCreationInfo walks the call stack to find the name the new object is assigned to, and compares the first local variable of each frame with the object. The comparison used in, which tests equality: an array compared element by element, and a variable that was not assigned yet was missing from f_locals. The comparison is now by identity, with f_locals.get, so an unset variable counts as a different object.

The tests in tests/test_signalobj_creation.py create a SignalObj from a function whose first local variable is an array and from one whose first local variable is not set yet. Both raised before this change.

Checked with Python 3.12, numpy 1.26 and scipy 1.17. The existing tests behave as on development: the 7 failures there (3 in test_h5io.py, 4 in test_pyttasave.py) are the same with and without this change.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

SignalObj looks for the name it is assigned to by walking the call stack
and comparing the first local variable of each frame with the new
object. The comparison used `in`, that is equality, so a caller whose
first local variable was a NumPy array raised "The truth value of an
array is ambiguous", and a caller whose first local variable was not yet
assigned raised KeyError. The comparison is now by identity, and an
unset variable counts as a different object.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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