55import tempfile
66from math import nan
77from pathlib import Path , PurePosixPath
8- from typing import TYPE_CHECKING , Iterable , Optional , Union
8+ from typing import TYPE_CHECKING , Iterable
99from urllib .parse import unquote , urlparse , urlunparse
1010from warnings import warn
1111
@@ -78,12 +78,12 @@ def __init__(
7878 mapping_df : pd .DataFrame = None ,
7979 extensions_config : dict = None ,
8080 ):
81- self .condition_df : Optional [ pd .DataFrame ] = condition_df
82- self .measurement_df : Optional [ pd .DataFrame ] = measurement_df
83- self .parameter_df : Optional [ pd .DataFrame ] = parameter_df
84- self .visualization_df : Optional [ pd .DataFrame ] = visualization_df
85- self .observable_df : Optional [ pd .DataFrame ] = observable_df
86- self .mapping_df : Optional [ pd .DataFrame ] = mapping_df
81+ self .condition_df : pd .DataFrame | None = condition_df
82+ self .measurement_df : pd .DataFrame | None = measurement_df
83+ self .parameter_df : pd .DataFrame | None = parameter_df
84+ self .visualization_df : pd .DataFrame | None = visualization_df
85+ self .observable_df : pd .DataFrame | None = observable_df
86+ self .mapping_df : pd .DataFrame | None = mapping_df
8787
8888 if any (
8989 (sbml_model , sbml_document , sbml_reader ),
@@ -109,7 +109,7 @@ def __init__(
109109 model_id = model_id ,
110110 )
111111
112- self .model : Optional [ Model ] = model
112+ self .model : Model | None = model
113113 self .extensions_config = extensions_config or {}
114114
115115 def __getattr__ (self , name ):
@@ -169,14 +169,12 @@ def __str__(self):
169169
170170 @staticmethod
171171 def from_files (
172- sbml_file : Union [str , Path ] = None ,
173- condition_file : Union [str , Path , Iterable [Union [str , Path ]]] = None ,
174- measurement_file : Union [str , Path , Iterable [Union [str , Path ]]] = None ,
175- parameter_file : Union [str , Path , Iterable [Union [str , Path ]]] = None ,
176- visualization_files : Union [
177- str , Path , Iterable [Union [str , Path ]]
178- ] = None ,
179- observable_files : Union [str , Path , Iterable [Union [str , Path ]]] = None ,
172+ sbml_file : str | Path = None ,
173+ condition_file : str | Path | Iterable [str | Path ] = None ,
174+ measurement_file : str | Path | Iterable [str | Path ] = None ,
175+ parameter_file : str | Path | Iterable [str | Path ] = None ,
176+ visualization_files : str | Path | Iterable [str | Path ] = None ,
177+ observable_files : str | Path | Iterable [str | Path ] = None ,
180178 model_id : str = None ,
181179 extensions_config : dict = None ,
182180 ) -> Problem :
@@ -252,7 +250,7 @@ def from_files(
252250 )
253251
254252 @staticmethod
255- def from_yaml (yaml_config : Union [ dict , Path , str ] ) -> Problem :
253+ def from_yaml (yaml_config : dict | Path | str ) -> Problem :
256254 """
257255 Factory method to load model and tables as specified by YAML file.
258256
@@ -308,7 +306,7 @@ def from_yaml(yaml_config: Union[dict, Path, str]) -> Problem:
308306 f"{ format_version .__format_version__ } ."
309307 )
310308 if yaml_config [FORMAT_VERSION ] == "2.0.0" :
311- warn ("Support for PEtab2.0 is experimental!" )
309+ warn ("Support for PEtab2.0 is experimental!" , stacklevel = 2 )
312310
313311 problem0 = yaml_config ["problems" ][0 ]
314312
@@ -421,7 +419,7 @@ def from_yaml(yaml_config: Union[dict, Path, str]) -> Problem:
421419 )
422420
423421 @staticmethod
424- def from_combine (filename : Union [ Path , str ] ) -> Problem :
422+ def from_combine (filename : Path | str ) -> Problem :
425423 """Read PEtab COMBINE archive (http://co.mbine.org/documents/archive).
426424
427425 See also :py:func:`petab.create_combine_archive`.
@@ -444,8 +442,7 @@ def from_combine(filename: Union[Path, str]) -> Problem:
444442
445443 archive = libcombine .CombineArchive ()
446444 if archive .initializeFromArchive (str (filename )) is None :
447- print (f"Invalid Combine Archive: { filename } " )
448- return None
445+ raise ValueError (f"Invalid Combine Archive: { filename } " )
449446
450447 with tempfile .TemporaryDirectory () as tmpdirname :
451448 archive .extractTo (tmpdirname )
@@ -458,7 +455,7 @@ def from_combine(filename: Union[Path, str]) -> Problem:
458455
459456 def to_files_generic (
460457 self ,
461- prefix_path : Union [ str , Path ] ,
458+ prefix_path : str | Path ,
462459 ) -> str :
463460 """Save a PEtab problem to generic file names.
464461
@@ -510,17 +507,17 @@ def to_files_generic(
510507
511508 def to_files (
512509 self ,
513- sbml_file : Union [ None , str , Path ] = None ,
514- condition_file : Union [ None , str , Path ] = None ,
515- measurement_file : Union [ None , str , Path ] = None ,
516- parameter_file : Union [ None , str , Path ] = None ,
517- visualization_file : Union [ None , str , Path ] = None ,
518- observable_file : Union [ None , str , Path ] = None ,
519- yaml_file : Union [ None , str , Path ] = None ,
520- prefix_path : Union [ None , str , Path ] = None ,
510+ sbml_file : None | str | Path = None ,
511+ condition_file : None | str | Path = None ,
512+ measurement_file : None | str | Path = None ,
513+ parameter_file : None | str | Path = None ,
514+ visualization_file : None | str | Path = None ,
515+ observable_file : None | str | Path = None ,
516+ yaml_file : None | str | Path = None ,
517+ prefix_path : None | str | Path = None ,
521518 relative_paths : bool = True ,
522- model_file : Union [ None , str , Path ] = None ,
523- mapping_file : Union [ None , str , Path ] = None ,
519+ model_file : None | str | Path = None ,
520+ mapping_file : None | str | Path = None ,
524521 ) -> None :
525522 """
526523 Write PEtab tables to files for this problem
@@ -573,7 +570,7 @@ def to_files(
573570 if prefix_path is not None :
574571 prefix_path = Path (prefix_path )
575572
576- def add_prefix (path0 : Union [ None , str , Path ] ) -> str :
573+ def add_prefix (path0 : None | str | Path ) -> str :
577574 return path0 if path0 is None else str (prefix_path / path0 )
578575
579576 model_file = add_prefix (model_file )
@@ -913,7 +910,7 @@ def get_optimization_to_simulation_parameter_mapping(self, **kwargs):
913910 )
914911 )
915912
916- def create_parameter_df (self , * args , * *kwargs ):
913+ def create_parameter_df (self , ** kwargs ):
917914 """Create a new PEtab parameter table
918915
919916 See :py:func:`create_parameter_df`.
@@ -924,7 +921,6 @@ def create_parameter_df(self, *args, **kwargs):
924921 observable_df = self .observable_df ,
925922 measurement_df = self .measurement_df ,
926923 mapping_df = self .mapping_df ,
927- * args ,
928924 ** kwargs ,
929925 )
930926
0 commit comments