88"""
99from __future__ import annotations
1010
11+ from typing import Any
1112import base64
1213from collections .abc import Callable , Iterable , Iterator , Sequence
1314import dataclasses
3738from ..type_hints import ArrayLike , NDArray
3839
3940#: Type of the function used to update a view.
40- ViewUpdateCallable = \
41- Callable [[Iterable [tuple [dataset .Dataset , str ]], str ], None ]
41+ ViewUpdateCallable = Callable [
42+ [Iterable [tuple [dataset .Dataset , str ]], str , list [Any ], dict [str ,
43+ Any ]], None ]
4244
4345#: Name of the file that contains the checksum of the view.
4446CHECKSUM_FILE = '.checksum'
@@ -350,28 +352,26 @@ def calculate_slice(
350352def _wrap_update_func (
351353 func : collection .UpdateCallable ,
352354 fs : fsspec .AbstractFileSystem ,
353- * args ,
354- ** kwargs ,
355355) -> ViewUpdateCallable :
356356 """Wrap an update function taking a list of partition's dataset and
357357 partition's path as input and returning None.
358358
359359 Args:
360360 func: The update function.
361361 fs: The file system used to access the variables in the view.
362- *args: The arguments of the update function.
363- **kwargs: The keyword arguments of the update function.
364362
365363 Returns:
366364 The wrapped function.
367365 """
368366
369367 def wrap_function (parameters : Iterable [tuple [dataset .Dataset , str ]],
370- base_dir : str ) -> None :
368+ base_dir : str , func_args : list [Any ],
369+ func_kwargs : dict [str , Any ]) -> None :
371370 """Wrap the function to be applied to the dataset."""
372371 for zds , partition in parameters :
373372 # Applying function on partition's data
374- dictionary : dict [str , ArrayLike ] = func (zds , * args , ** kwargs )
373+ dictionary : dict [str , ArrayLike ] = func (zds , * func_args ,
374+ ** func_kwargs )
375375 tuple (
376376 update_zarr_array ( # type: ignore[func-returns-value]
377377 dirname = join_path (base_dir , partition , varname ),
@@ -389,8 +389,6 @@ def _wrap_update_func_overlap(
389389 fs : fsspec .AbstractFileSystem ,
390390 view_ref : collection .Collection ,
391391 trim : bool ,
392- * args ,
393- ** kwargs ,
394392) -> ViewUpdateCallable :
395393 """Wrap an update function taking a list of partition's dataset and
396394 partition's path as input and returning None.
@@ -402,8 +400,6 @@ def _wrap_update_func_overlap(
402400 fs: The file system used to access the variables in the view.
403401 view_ref: The view reference.
404402 trim: If True, trim the dataset to the overlap.
405- *args: The arguments of the update function.
406- **kwargs: The keyword arguments of the update function.
407403
408404 Returns:
409405 The wrapped function.
@@ -414,7 +410,8 @@ def _wrap_update_func_overlap(
414410 raise ValueError ('The depth must be positive' )
415411
416412 def wrap_function (parameters : Iterable [tuple [dataset .Dataset , str ]],
417- base_dir : str ) -> None :
413+ base_dir : str , func_args : list [Any ],
414+ func_kwargs : dict [str , Any ]) -> None :
418415 """Wrap the function to be applied to the dataset."""
419416 zds : dataset .Dataset
420417 indices : slice
@@ -425,15 +422,15 @@ def wrap_function(parameters: Iterable[tuple[dataset.Dataset, str]],
425422 # pylint: disable=duplicate-code
426423 # False positive with the function _wrap_update_func_with_overlap
427424 # defined in the module zcollection.collection.detail
428- _update_with_overlap (* args ,
425+ _update_with_overlap (* func_args ,
429426 func = func ,
430427 zds = zds ,
431428 indices = indices ,
432429 dim = dim ,
433430 fs = fs ,
434431 path = join_path (base_dir , partition ),
435432 trim = trim ,
436- ** kwargs )
433+ ** func_kwargs )
437434 # pylint: enable=duplicate-code
438435
439436 return wrap_function
0 commit comments