MCPcopy Index your code
hub / github.com/pydata/xarray / prepare_variable

Method prepare_variable

xarray/backends/scipy_.py:328–357  ·  view source on GitHub ↗
(
        self,
        name: str,
        variable: Variable,
        check_encoding: bool = False,
        unlimited_dims: set[str] | None = None,
    )

Source from the content-addressed store, hash-verified

326 return variable
327
328 def prepare_variable(
329 self,
330 name: str,
331 variable: Variable,
332 check_encoding: bool = False,
333 unlimited_dims: set[str] | None = None,
334 ) -> tuple[ScipyArrayWrapper, Any]:
335 if (
336 check_encoding
337 and variable.encoding
338 and variable.encoding != {"_FillValue": None}
339 ):
340 raise ValueError(
341 f"unexpected encoding for scipy backend: {list(variable.encoding)}"
342 )
343
344 data = variable.data
345 # nb. this still creates a numpy array in all memory, even though we
346 # don't write the data yet; scipy.io.netcdf does not support incremental
347 # writes.
348 if name not in self.ds.variables:
349 self.ds.createVariable(name, data.dtype, [str(v) for v in variable.dims])
350 scipy_var = self.ds.variables[name]
351 for k, v in variable.attrs.items():
352 self._validate_attr_key(k)
353 setattr(scipy_var, k, v)
354
355 target = ScipyArrayWrapper(name, self)
356
357 return target, data
358
359 def sync(self) -> None:
360 self.ds.sync()

Callers

nothing calls this directly

Calls 3

_validate_attr_keyMethod · 0.95
ScipyArrayWrapperClass · 0.85
itemsMethod · 0.80

Tested by

no test coverage detected