MCPcopy
hub / github.com/pydata/xarray / process_subset_opt

Function process_subset_opt

xarray/structure/concat.py:419–550  ·  view source on GitHub ↗
(
        opt: ConcatOptions | Iterable[Hashable] | CombineKwargDefault,
        subset: Literal["coords", "data_vars"],
    )

Source from the content-addressed store, hash-verified

417 concat_dim_lengths.append(ds.sizes.get(dim, 1))
418
419 def process_subset_opt(
420 opt: ConcatOptions | Iterable[Hashable] | CombineKwargDefault,
421 subset: Literal["coords", "data_vars"],
422 ) -> None:
423 original = set(concat_over)
424 compat_str = (
425 compat._value if isinstance(compat, CombineKwargDefault) else compat
426 )
427 assert compat_str is not None
428 if isinstance(opt, str | CombineKwargDefault):
429 if opt == "different":
430 if isinstance(compat, CombineKwargDefault) and compat != "override":
431 if not isinstance(opt, CombineKwargDefault):
432 emit_user_level_warning(
433 compat.warning_message(
434 "This change will result in the following ValueError: "
435 f"Cannot specify both {subset}='different' and compat='override'.",
436 recommend_set_options=False,
437 ),
438 FutureWarning,
439 )
440
441 if compat == "override":
442 raise ValueError(
443 f"Cannot specify both {subset}='different' and compat='override'."
444 + (
445 compat.error_message()
446 if isinstance(compat, CombineKwargDefault)
447 else ""
448 )
449 )
450 # all nonindexes that are not the same in each dataset
451 for k in getattr(datasets[0], subset):
452 if k not in concat_over:
453 equal = None
454
455 variables = [
456 ds.variables[k] for ds in datasets if k in ds.variables
457 ]
458
459 if len(variables) == 1:
460 # coords="different" doesn't make sense when only one object
461 # contains a particular variable.
462 break
463 elif len(variables) != len(datasets) and opt == "different":
464 raise ValueError(
465 f"{k!r} not present in all datasets and coords='different'. "
466 f"Either add {k!r} to datasets where it is missing or "
467 "specify coords='minimal'."
468 )
469
470 # first check without comparing values i.e. no computes
471 for var in variables[1:]:
472 equal = getattr(variables[0], compat_str)(
473 var, equiv=lazy_array_equiv
474 )
475 if equal is not True:
476 # exit early if we know these are not equal or that

Callers 1

_calc_concat_overFunction · 0.85

Calls 7

emit_user_level_warningFunction · 0.90
warning_messageMethod · 0.80
error_messageMethod · 0.80
addMethod · 0.45
loadMethod · 0.45
computeMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…