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

Function calculate_dimensions

xarray/core/variable.py:3137–3160  ·  view source on GitHub ↗

Calculate the dimensions corresponding to a set of variables. Returns dictionary mapping from dimension names to sizes. Raises ValueError if any of the dimension sizes conflict.

(variables: Mapping[Any, Variable])

Source from the content-addressed store, hash-verified

3135
3136
3137def calculate_dimensions(variables: Mapping[Any, Variable]) -> dict[Hashable, int]:
3138 """Calculate the dimensions corresponding to a set of variables.
3139
3140 Returns dictionary mapping from dimension names to sizes. Raises ValueError
3141 if any of the dimension sizes conflict.
3142 """
3143 dims: dict[Hashable, int] = {}
3144 last_used = {}
3145 scalar_vars = {k for k, v in variables.items() if not v.dims}
3146 for k, var in variables.items():
3147 for dim, size in zip(var.dims, var.shape, strict=True):
3148 if dim in scalar_vars:
3149 raise ValueError(
3150 f"dimension {dim!r} already exists as a scalar variable"
3151 )
3152 if dim not in dims:
3153 dims[dim] = size
3154 last_used[dim] = k
3155 elif dims[dim] != size:
3156 raise ValueError(
3157 f"conflicting sizes for dimension {dim!r}: "
3158 f"length {size} on {k!r} and length {dims[dim]} on {last_used!r}"
3159 )
3160 return dims

Callers 15

_construct_directMethod · 0.90
__delitem__Method · 0.90
_calculate_binary_opMethod · 0.90
_update_coordsMethod · 0.90
dimsMethod · 0.90
get_all_dimsMethod · 0.90
merge_coreFunction · 0.90
reindex_variablesFunction · 0.90
find_matching_indexesMethod · 0.90

Calls 1

itemsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…