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

Function infer_template

xarray/core/parallel.py:119–139  ·  view source on GitHub ↗

Infer return object by running the function on meta objects.

(
    func: Callable[..., T_Xarray], obj: DataArray | Dataset, *args, **kwargs
)

Source from the content-addressed store, hash-verified

117
118
119def infer_template(
120 func: Callable[..., T_Xarray], obj: DataArray | Dataset, *args, **kwargs
121) -> T_Xarray:
122 """Infer return object by running the function on meta objects."""
123 meta_args = [make_meta(arg) for arg in (obj,) + args]
124
125 try:
126 template = func(*meta_args, **kwargs)
127 except Exception as e:
128 raise Exception(
129 "Cannot infer object returned from running user provided function. "
130 "Please supply the 'template' kwarg to map_blocks."
131 ) from e
132
133 if not isinstance(template, Dataset | DataArray):
134 raise TypeError(
135 "Function must return an xarray DataArray or Dataset. Instead it returned "
136 f"{type(template)}"
137 )
138
139 return template
140
141
142def make_dict(x: DataArray | Dataset) -> dict[Hashable, Any]:

Callers 1

map_blocksFunction · 0.85

Calls 3

make_metaFunction · 0.85
typeFunction · 0.85
funcFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…