zcollection.view.View.update#

View.update(func, /, *args, depth=0, delayed=True, filters=None, npartitions=None, selected_variables=None, trim=True, **kwargs)[source]#

Update a variable stored int the view.

Parameters:
  • func (UpdateCallable) – The function to apply to calculate the new values for the target variables.

  • depth (int) – The depth of the overlap between the partitions. Default is 0 (no overlap). If depth is greater than 0, the function is applied on the partition and its neighbors selected by the depth. If func accepts a partition_info as a keyword argument, it will be passed a tuple with the name of the partitioned dimension and the slice allowing getting in the dataset the selected partition without the overlap.

  • delayed (bool) – Whether to load data in a dask array or in memory.

  • filters (str | Callable[[Dict[str, int]], bool] | None) – The predicate used to filter the partitions to drop. To get more information on the predicate, see the documentation of the Collection.partitions method.

  • npartitions (int | None) – The number of partitions to update in parallel. By default, it is equal to the number of Dask workers available when calling this method.

  • selected_variables (Iterable[str] | None) – A list of variables to retain from the view. If None, all variables are loaded. Useful to load only a subset of the view.

  • trim (bool) – Whether to trim depth items from each partition after calling func. Set it to False if your function does this for you.

  • args – The positional arguments to pass to the function.

  • kwargs – The keyword arguments to pass to the function.

Raises:
  • ValueError – If the variable does not exist or if the variable belongs to the reference collection.

  • ValueError – If the depth is greater than 0 and the selected variables does not contain the variables updated by the function.

Return type:

None

Example

>>> def temp_celsius_to_kelvin(
...     dataset: zcollection.dataset.Dataset,
... ) -> Dict[str, numpy.ndarray]:
...     return dict(
...         temperature_kelvin=dataset["temperature"].values + 273,
...         15)
>>> view.update(update_temperature)