Fix variable array write semantics and VariableWait state handling#1144
Merged
Conversation
This commit updates the BaseVariable class to ensure that indexed writes into ndarray-backed variables correctly handle scalar elements. It modifies the value assignment logic to convert 0-D ndarrays to scalars when necessary, improving data integrity during variable updates. Additionally, it refines index handling for single entry items to support both list and non-list index types. This bug was found by the new test harness.
This commit modifies the VariableWaitClass to initialize the 'updated' state of variable values to False upon addition, and updates the state to True when a variable is modified. Additionally, the VariableValue class is updated to include an 'updated' attribute, enhancing the tracking of variable changes within the PyRogue framework.
ruck314
approved these changes
Mar 18, 2026
Contributor
|
This all looks ok. Only concern might be the number of ifs added and impact on performance. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## pre-release #1144 +/- ##
===============================================
- Coverage 32.55% 32.51% -0.05%
===============================================
Files 68 68
Lines 7147 7163 +16
Branches 1009 1014 +5
===============================================
+ Hits 2327 2329 +2
- Misses 4655 4668 +13
- Partials 165 166 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Bug Fixes
BaseVariable
_setDict()failed on single-index array keysWhat was broken:
"1"were evaluated to scalar1, but the code assumed a subscriptable result and indexed[0].Inputs that triggered it:
_setDict().Example:
root.CmdDev.RemoteArray._setDict("99", writeEach=False, modes=["RW"], keys=["1"])Previous failure:
TypeError: 'int' object is not subscriptableFix:
Indexed
setDisp()on ndarray-backed variables passed a 0-D ndarray instead of a scalarWhat was broken:
parseDisp("99")for ndarray-backed variables can produce a 0-D ndarray.Inputs that triggered it:
Example:
root.CmdDev.RemoteArray.setDisp("99", index=1)Result:
Fix:
.item()before indexedset()calls.VariableWaitClass.get_values()used variable objects instead of stored path keysWhat was broken:
v.path.get_values()tried to fetch entries using the variable objects themselves.Inputs that triggered it:
get_values()afterVariableWaitClass.wait().Example:
waiter = VariableWaitClass(root.Dev.Counter, timeout=...)waiter.wait()waiter.get_values()Fix:
{variable_object: cached_value_by_path}usingk.pathinternally.Documented
VariableValue.updatedfield did not actually existWhat was broken:
VariableWaitdocs describevarValues[i].updated.VariableValuehad no such field, and wait updates never set it.Inputs that triggered it:
VariableWaitpredicate using update-state semantics rather than raw value comparisons.Example:
VariableWait([var1, var2], lambda vals: vals[0].updated and vals[1].updated, timeout=...)Fix:
updated = FalsetoVariableValueFalseon armTrueinVariableWaitClass._varUpdate()Variable-array YAML slices did not support scalar broadcast
What was broken:
SomeArrayValue[*]: valueSomeArrayValue[:]: valueSomeArrayValue[1:3]: valuedid not support a scalar value.
Inputs that triggered it:
setYaml()call that assigned a scalar to an array-variable slice.Example failure:
SomeArrayValue[1:3]: 7TypeError: 'int' object is not iterableFix:
BaseVariable._setDict()so a single scalar value broadcasts across the selected slice.