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

Function make_meta

xarray/core/parallel.py:91–116  ·  view source on GitHub ↗

If obj is a DataArray or Dataset, return a new object of the same type and with the same variables and dtypes, but where all variables have size 0 and numpy backend. If obj is neither a DataArray nor Dataset, return it unaltered.

(obj)

Source from the content-addressed store, hash-verified

89
90
91def make_meta(obj):
92 """If obj is a DataArray or Dataset, return a new object of the same type and with
93 the same variables and dtypes, but where all variables have size 0 and numpy
94 backend.
95 If obj is neither a DataArray nor Dataset, return it unaltered.
96 """
97 if isinstance(obj, DataArray):
98 obj_array = obj
99 obj = dataarray_to_dataset(obj)
100 elif isinstance(obj, Dataset):
101 obj_array = None
102 else:
103 return obj
104
105 from dask.array.utils import meta_from_array
106
107 meta = Dataset()
108 for name, variable in obj.variables.items():
109 meta_obj = meta_from_array(variable.data, ndim=variable.ndim)
110 meta[name] = (variable.dims, meta_obj, variable.attrs)
111 meta.attrs = obj.attrs
112 meta = meta.set_coords(obj.coords)
113
114 if obj_array is not None:
115 return dataset_to_dataarray(meta)
116 return meta
117
118
119def infer_template(

Callers 2

test_make_metaFunction · 0.90
infer_templateFunction · 0.85

Calls 5

set_coordsMethod · 0.95
DatasetClass · 0.90
dataarray_to_datasetFunction · 0.85
dataset_to_dataarrayFunction · 0.85
itemsMethod · 0.80

Tested by 1

test_make_metaFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…