Error Embedded Python Code - sqlalchemy

Hello,
I am trying to retrieve data from a database table using sqlalchemy

Set
sec sectors     
;

$onEmbeddedCode Python:
import sqlalchemy
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mssql://LAPTOP-HdfDNQL8E4/POLIFOLIO_DB?driver=SQL+Server+Native+Client+11.0?trusted_connection=yes')
sec = pd.read_sql_query('select distinct cast(SECTORID AS INT) from pf_actions', engine)
df = pd.DataFrame(sec)
gams.set('sec', [tuple(x) for x in df.values.tolist()])
$offEmbeddedCode sec

sectorid is a column with decimals.
Unfortunately it returns an error
Cannot load/unload symbol with unknown dimension:

How can i load my data to “sec” set?

Hi,

As the error message indicates, you get the problem, since GAMS does not know the dimension of the symbol “sec” in your code. You can set it, for example, in the declaration like this to define “sec” as one dimensional set:

Set
sec(*) sectors     
;

Hope that helps,
Lutz