Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion andes/core/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,17 @@ def set(self, src, idx, attr, value):
uid = self.idx2uid(idx)
instance = self.__dict__[src]

instance.__dict__[attr][uid] = value
# Check if the destination is a list
if isinstance(instance.__dict__[attr], list):
# Use a for-loop to set values
if isinstance(uid, list):
for i, u in enumerate(uid):
instance.__dict__[attr][u] = value[i]
else:
instance.__dict__[attr][uid] = value
else:
# Default behavior for numpy arrays or other types
instance.__dict__[attr][uid] = value

# update differential equations' time constants stored in `dae.Tf`

Expand Down
8 changes: 7 additions & 1 deletion andes/interop/pandapower.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
from andes.shared import pd, rad2deg, deg2rad
from andes.shared import pandapower as pp

try:
nan = np.nan
except AttributeError:
# for older numpy versions
nan = np.NAN

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -315,7 +321,7 @@ def _to_pp_line(ssa, ssp, ssa_bus):
tf_df['parallel'] = 1
tf_df['oltc'] = False
tf_df['tap_phase_shifter'] = False
tf_df['tap_step_degree'] = np.NaN
tf_df['tap_step_degree'] = np.nan
tf_df['df'] = 1
tf_df['std_type'] = None

Expand Down
4 changes: 4 additions & 0 deletions docs/source/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ The APIs before v3.0.0 are in beta and may change without prior notice.
v1.9 Notes
==========

v1.9.4 (2025-xx-xx)
-------------------
- Enhance ``Model.set()`` to support assigning values when the destination is a list.

v1.9.3 (2025-01-05)
-------------------
Development of connectivity manager ``ConnMan``:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_model_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def test_model_set(self):
np.testing.assert_equal(ss.GENROU.M.v[3], 6.0)
self.assertEqual(ss.TDS.Teye[omega_addr[3], omega_addr[3]], 6.0)

# set when destination idx is list
ss.Bus.set(src='name', attr='v', idx=(1, 2, 3), value=['A', 'B', 'C'])
self.assertEqual(ss.Bus.name.v[:3], ['A', 'B', 'C'])

def test_find_idx(self):
ss = andes.load(andes.get_case('ieee14/ieee14_pvd1.xlsx'))
mdl = ss.PVD1
Expand Down Expand Up @@ -131,3 +135,7 @@ def test_model_alter(self):
# alter `vin` on instances without `vin` falls back to `v`
ss.GENCLS.alter(src='p0', idx=2, value=1, attr='vin')
self.assertEqual(ss.GENCLS.p0.v[1], 1)

# # alter `v` when destination idx is list
ss.Bus.alter(src='name', idx=[0, 1], value=['A', 'B'], attr='vin')
np.testing.assert_equal(ss.Bus.name.v[:2], ['A', 'B'])