@@ -2348,6 +2348,33 @@ def _print_xml(doc):
23482348 return result .replace (" " , "\n " )
23492349
23502350
2351+ def _combine_options_asdict (options : str | dict | None ) -> dict :
2352+ """Convert any valid combine options into an options dictionary."""
2353+ from iris import LOAD_POLICY
2354+
2355+ if options is None :
2356+ opts_dict = LOAD_POLICY .settings ()
2357+ elif isinstance (options , dict ):
2358+ opts_dict = options
2359+ elif isinstance (options , str ):
2360+ if options in LOAD_POLICY .SETTINGS :
2361+ opts_dict = LOAD_POLICY .SETTINGS [options ]
2362+ else :
2363+ msg = (
2364+ "Unrecognised settings name : expected one of "
2365+ f"{ tuple (LOAD_POLICY .SETTINGS )} ."
2366+ )
2367+ raise ValueError (msg )
2368+ else :
2369+ msg = ( # type: ignore[unreachable]
2370+ f"arg 'options' has type { type (options )!r} , "
2371+ "expected one of (str | dict | None)"
2372+ )
2373+ raise ValueError (msg ) # type: ignore[unreachable]
2374+
2375+ return opts_dict
2376+
2377+
23512378def combine_cubes (
23522379 cubes : List [Cube ],
23532380 options : str | dict | None = None ,
@@ -2450,30 +2477,9 @@ def testcube(timepts):
24502477
24512478 """
24522479 # TODO: somehow, provide a real + useful working code example
2453-
2454- from iris import LOAD_POLICY , CombineOptions
24552480 from iris ._combine import _combine_cubes
24562481
2457- if options is None :
2458- opts_dict = LOAD_POLICY .settings ()
2459- elif isinstance (options , str ):
2460- if options in CombineOptions .SETTINGS :
2461- opts_dict = CombineOptions .SETTINGS [options ]
2462- else :
2463- msg = (
2464- "Unrecognised settings name : expected one of "
2465- f"{ tuple (CombineOptions .SETTINGS )} ."
2466- )
2467- raise ValueError (msg )
2468- elif isinstance (options , dict ):
2469- opts_dict = options
2470- else :
2471- msg = ( # type: ignore[unreachable]
2472- f"arg 'options' has type { type (options )!r} , "
2473- "expected one of (str | dict | None)"
2474- )
2475- raise ValueError (msg ) # type: ignore[unreachable]
2476-
2482+ opts_dict = _combine_options_asdict (options )
24772483 if kwargs is not None :
24782484 opts_dict = opts_dict .copy () # avoid changing original
24792485 opts_dict .update (kwargs )
0 commit comments