8
8
"""
9
9
from __future__ import annotations
10
10
11
+ from typing import Any
11
12
import base64
12
13
from collections .abc import Callable , Iterable , Iterator , Sequence
13
14
import dataclasses
37
38
from ..type_hints import ArrayLike , NDArray
38
39
39
40
#: 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 ]
42
44
43
45
#: Name of the file that contains the checksum of the view.
44
46
CHECKSUM_FILE = '.checksum'
@@ -350,28 +352,26 @@ def calculate_slice(
350
352
def _wrap_update_func (
351
353
func : collection .UpdateCallable ,
352
354
fs : fsspec .AbstractFileSystem ,
353
- * args ,
354
- ** kwargs ,
355
355
) -> ViewUpdateCallable :
356
356
"""Wrap an update function taking a list of partition's dataset and
357
357
partition's path as input and returning None.
358
358
359
359
Args:
360
360
func: The update function.
361
361
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.
364
362
365
363
Returns:
366
364
The wrapped function.
367
365
"""
368
366
369
367
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 :
371
370
"""Wrap the function to be applied to the dataset."""
372
371
for zds , partition in parameters :
373
372
# 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 )
375
375
tuple (
376
376
update_zarr_array ( # type: ignore[func-returns-value]
377
377
dirname = join_path (base_dir , partition , varname ),
@@ -389,8 +389,6 @@ def _wrap_update_func_overlap(
389
389
fs : fsspec .AbstractFileSystem ,
390
390
view_ref : collection .Collection ,
391
391
trim : bool ,
392
- * args ,
393
- ** kwargs ,
394
392
) -> ViewUpdateCallable :
395
393
"""Wrap an update function taking a list of partition's dataset and
396
394
partition's path as input and returning None.
@@ -402,8 +400,6 @@ def _wrap_update_func_overlap(
402
400
fs: The file system used to access the variables in the view.
403
401
view_ref: The view reference.
404
402
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.
407
403
408
404
Returns:
409
405
The wrapped function.
@@ -414,7 +410,8 @@ def _wrap_update_func_overlap(
414
410
raise ValueError ('The depth must be positive' )
415
411
416
412
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 :
418
415
"""Wrap the function to be applied to the dataset."""
419
416
zds : dataset .Dataset
420
417
indices : slice
@@ -425,15 +422,15 @@ def wrap_function(parameters: Iterable[tuple[dataset.Dataset, str]],
425
422
# pylint: disable=duplicate-code
426
423
# False positive with the function _wrap_update_func_with_overlap
427
424
# defined in the module zcollection.collection.detail
428
- _update_with_overlap (* args ,
425
+ _update_with_overlap (* func_args ,
429
426
func = func ,
430
427
zds = zds ,
431
428
indices = indices ,
432
429
dim = dim ,
433
430
fs = fs ,
434
431
path = join_path (base_dir , partition ),
435
432
trim = trim ,
436
- ** kwargs )
433
+ ** func_kwargs )
437
434
# pylint: enable=duplicate-code
438
435
439
436
return wrap_function
0 commit comments