Skip to content

Commit 5f95b76

Browse files
committed
Batch/Obj: tweak object setter type priority to allow batch.ObjRef = [object, ...]
1 parent 9513534 commit 5f95b76

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

altdss/Batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def _set_batch_obj_prop(self, idx: int, other: Optional[Union[DSSObj, List[DSSOb
529529
self._check_for_error()
530530
return
531531

532-
if other is not None or isinstance(other, (bytes, str)) or (isinstance(other, LIST_LIKE) and len(other) and isinstance(other[0], (bytes, str))):
532+
if (other is not None and isinstance(other, (bytes, str))) or (isinstance(other, LIST_LIKE) and len(other) and isinstance(other[0], (bytes, str))):
533533
self._set_batch_string(idx, other, flags)
534534
return
535535

docs/changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ relevant. See [DSS C-API's repository](https://github.com/dss-extensions/dss_cap
1111
- Implement `OCPDevice`
1212

1313
- NonUniformBatch: allow `batch[idx]` to get a single element by index.
14-
- Setters: allow using `None` to clear object references (e.g. `altdss.Load[0].Daily = None`)
14+
- Setters:
15+
- Allow using `None` to clear object references (e.g. `altdss.Load[0].Daily = None`)
16+
- Allow using list of live objects to fill a property that represents a DSS object.
1517
- ArrayProxy:
1618
- Fix `BatchFloat64ArrayProxy.to_list()`. It was returning an array instead a list.
1719
- Accepts lists for in-place sub, e.g. `arrayProxy -= [1.1, 1.4]` now works as expected.

tests/test_obj.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,42 @@ def test_no_new_attr():
764764
loads.non_existent_attribute_should_fail = True
765765

766766

767+
def test_obj_setter():
768+
create_ref_ckt13(altdss)
769+
altdss.Load.Daily = 'default'
770+
default_shape = altdss.LoadShape['default']
771+
assert all(l.Daily == default_shape for l in altdss.Load)
772+
773+
create_ref_ckt13(altdss)
774+
altdss.Load.Daily_str = 'default'
775+
default_shape = altdss.LoadShape['default']
776+
assert all(l.Daily == default_shape for l in altdss.Load)
777+
778+
create_ref_ckt13(altdss)
779+
default_shape = altdss.LoadShape['default']
780+
altdss.Load.Daily = default_shape
781+
assert all(l.Daily_str == 'default' for l in altdss.Load)
782+
assert all(l.Daily == default_shape for l in altdss.Load)
783+
784+
create_ref_ckt13(altdss)
785+
default_shape = altdss.LoadShape['default']
786+
altdss.Load.Daily = ['default'] * len(altdss.Load)
787+
assert all(l.Daily_str == 'default' for l in altdss.Load)
788+
assert all(l.Daily == default_shape for l in altdss.Load)
789+
790+
create_ref_ckt13(altdss)
791+
default_shape = altdss.LoadShape['default']
792+
altdss.Load.Daily_str = ['default'] * len(altdss.Load)
793+
assert all(l.Daily_str == 'default' for l in altdss.Load)
794+
assert all(l.Daily == default_shape for l in altdss.Load)
795+
796+
create_ref_ckt13(altdss)
797+
default_shape = altdss.LoadShape['default']
798+
altdss.Load.Daily = [default_shape] * len(altdss.Load)
799+
assert all(l.Daily_str == 'default' for l in altdss.Load)
800+
assert all(l.Daily == default_shape for l in altdss.Load)
801+
802+
767803
if __name__ == '__main__':
768804
# Adjust for manual running a test-case
769805
test_register_values()

0 commit comments

Comments
 (0)