Skip to content

A potential unexpected behavior in model.set when idx is integer #595

@jinningwang

Description

@jinningwang

Describe the bug

Error info:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[11], line 1
----> 1 ss.GENROU.set(src='coi', attr='v', idx=[1, 2],
      2               value=('COI_1', 'COI_1'))

File ~/work/miniconda3/envs/amsre/lib/python3.12/site-packages/andes/core/model/model.py:511, in Model.set(self, src, idx, attr, value)
    508 uid = self.idx2uid(idx)
    509 instance = self.__dict__[src]
--> 511 instance.__dict__[attr][uid] = value
    513 # update differential equations' time constants stored in `dae.Tf`
    515 if attr == "v":

TypeError: list indices must be integers or slices, not list

To Reproduce

import andes
ss = andes.load(andes.get_case('kundur/kundur_full.xlsx'), setup=False)
ss.COI.add(idx='COI_1')
ss.GENROU.set(src='coi', attr='v', idx=[1, 2], value=('COI_1', 'COI_1'))

Expected behavior

A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: [e.g. Windows]
  • ANDES version (please paste the output from andes misc --version)
(amsre) jinningwang@jwangMBP demo % andes

    _           _         | Version 1.9.3
   /_\  _ _  __| |___ ___ | Python 3.12.0 on Darwin, 04/05/2025 12:32:37 PM
  / _ \| ' \/ _` / -_|_-< | 
 /_/ \_\_||_\__,_\___/__/ | This program comes with ABSOLUTELY NO WARRANTY.

usage: andes [-h] [-v {1,10,20,30,40}] {run,plot,doc,misc,prepare,prep,selftest,st,demo} ...

positional arguments:
  {run,plot,doc,misc,prepare,prep,selftest,st,demo}
                        [run] run simulation routine; [plot] plot results; [doc] quick documentation; [misc]
                        misc. functions; [prepare] prepare the numerical code; [selftest] run self test;

options:
  -h, --help            show this help message and exit
  -v {1,10,20,30,40}, --verbose {1,10,20,30,40}
                        Verbosity level in 10-DEBUG, 20-INFO, 30-WARNING, or 40-ERROR.
(amsre) jinningwang@jwangMBP demo % andes misc --version
Python  3.12.0
andes   1.9.3
numpy   1.26.0
kvxopt  1.3.2.1
sympy   1.13.3
scipy   1.13.1
pandas  2.2.2
numba   0.60.0

**pip packages (please paste the output from pip list)

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions