@@ -588,7 +588,6 @@ def _generate_gams_string(
588588 def _filter_load_symbols (
589589 self ,
590590 symbol_names : dict [str , str ] | list [str ],
591- create_if_not_declared : bool = False ,
592591 ) -> dict [str , str ] | list [str ]:
593592 if isinstance (symbol_names , list ):
594593 names = []
@@ -598,12 +597,7 @@ def _filter_load_symbols(
598597 if not isinstance (symbol , gt .Alias ) and symbol .synchronize :
599598 names .append (name )
600599 else :
601- if create_if_not_declared :
602- names .append (name )
603- else :
604- raise ValidationError (
605- f"Cannot load records of `{ name } ` because it does not exist in the container."
606- )
600+ names .append (name )
607601
608602 return names
609603
@@ -619,13 +613,7 @@ def _filter_load_symbols(
619613
620614 return mapping
621615
622- def _load_records_from_gdx (
623- self ,
624- load_from : str ,
625- names : Iterable [str ],
626- * ,
627- create_if_not_declared : bool = False ,
628- ) -> None :
616+ def _load_records_from_gdx (self , load_from : str , names : Iterable [str ]) -> None :
629617 self ._temp_container .read (load_from , names )
630618 original_state = self ._options .miro_protect
631619 self ._options .miro_protect = False
@@ -636,12 +624,7 @@ def _load_records_from_gdx(
636624 self [name ].records = updated_records
637625 self [name ].domain_labels = self [name ].domain_names
638626 else :
639- if create_if_not_declared :
640- self ._read (load_from , [name ])
641- else :
642- raise ValidationError (
643- f"Cannot load records of `{ name } ` because it does not exist in the container."
644- )
627+ self ._read (load_from , [name ])
645628
646629 self ._options .miro_protect = original_state
647630 self ._temp_container .data = {}
@@ -989,54 +972,28 @@ def loadRecordsFromGdx(
989972 if isinstance (load_from , Path ):
990973 load_from = str (load_from .resolve ())
991974
992- create_if_not_declared = symbol_names is None
993975 if symbol_names is None :
994976 # If no symbol names are given, all records in the gdx should be loaded
995977 symbol_names = utils ._get_symbol_names_from_gdx (
996978 self .system_directory , load_from
997979 )
998980 self ._add_statement (f"$declareAndLoad { load_from } " )
999- symbol_names = self ._filter_load_symbols (
1000- symbol_names , # type: ignore
1001- create_if_not_declared ,
1002- )
1003- self ._load_records_from_gdx (
1004- load_from , symbol_names , create_if_not_declared = create_if_not_declared
1005- )
981+ symbol_names = self ._filter_load_symbols (symbol_names ) # type: ignore
982+ self ._load_records_from_gdx (load_from , symbol_names )
1006983 self ._synch_with_gams ()
1007984 return
1008985
1009- if isinstance (symbol_names , list ):
1010- symbol_names = self ._filter_load_symbols (
1011- symbol_names , create_if_not_declared
1012- )
1013- self ._add_statement (f"$gdxIn { load_from } " )
1014- symbols_str = " " .join (symbol_names )
1015- self ._add_statement (f"$loadDC { symbols_str } " )
1016- self ._add_statement ("$gdxIn" )
1017- elif isinstance (symbol_names , dict ):
1018- symbol_names = self ._filter_load_symbols (
1019- symbol_names , create_if_not_declared
1020- )
1021- self ._add_statement (f"$gdxIn { load_from } " )
1022- symbols_str = " " .join (
1023- [f"{ value } ={ key } " for key , value in symbol_names .items ()] # type: ignore
1024- )
1025- self ._add_statement (f"$loadDC { symbols_str } " )
1026- self ._add_statement ("$gdxIn" )
986+ if isinstance (symbol_names , (list , dict )):
987+ symbol_names = self ._filter_load_symbols (symbol_names )
1027988 else :
1028989 raise TypeError ("`symbol_names` must be either a list or a dictionary." )
1029990
1030- self ._options ._debug_options ["gdx" ] = self ._gdx_out
1031- self ._options ._debug_options ["gdxSymbols" ] = "newOrChanged"
1032- self ._synch_with_gams ()
1033-
1034991 if isinstance (symbol_names , dict ):
1035992 self ._load_records_with_rename (load_from , symbol_names )
1036993 else :
1037- self ._load_records_from_gdx (
1038- load_from , symbol_names , create_if_not_declared = create_if_not_declared
1039- )
994+ self ._load_records_from_gdx (load_from , symbol_names )
995+
996+ self . _synch_with_gams ( )
1040997
1041998 def addGamsCode (self , gams_code : str ) -> None :
1042999 """
0 commit comments