



'''simple docstring'''


import pytest

from datasets.parallel import ParallelBackendConfig, parallel_backend
from datasets.utils.py_utils import map_nested

from .utils import require_dill_gt_0_3_2, require_joblibspark, require_not_windows






def  UpperCAmelCase_       (		lowercase__       ):  # picklable for multiprocessing


     '''simple docstring'''







     return i + 1






@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def  UpperCAmelCase_       (		):


     '''simple docstring'''







     with parallel_backend("spark"       ):
          assert ParallelBackendConfig.backend_name == "spark"

     a_       		=[1, 2, 3]
     with pytest.raises(lowercase__       ):
          with parallel_backend("unsupported backend"       ):
               map_nested(lowercase__       ,	lowercase__       ,	num_proc=2       )

     with pytest.raises(lowercase__       ):
          with parallel_backend("unsupported backend"       ):
               map_nested(lowercase__       ,	lowercase__       ,	num_proc=-1       )






@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize("num_proc"       ,	[2, -1]       )
def  UpperCAmelCase_       (		lowercase__       ):


     '''simple docstring'''







     a_       		=[1, 2]
     a_       		={"a": 1, "b": 2}
     a_       		={"a": [1, 2], "b": [3, 4]}
     a_       		={"a": {"1": 1}, "b": 2}
     a_       		={"a": 1, "b": 2, "c": 3, "d": 4}
     a_       		=[2, 3]
     a_       		={"a": 2, "b": 3}
     a_       		={"a": [2, 3], "b": [4, 5]}
     a_       		={"a": {"1": 2}, "b": 3}
     a_       		={"a": 2, "b": 3, "c": 4, "d": 5}

     with parallel_backend("spark"       ):
          assert map_nested(lowercase__       ,	lowercase__       ,	num_proc=lowercase__       ) == expected_map_nested_sa
          assert map_nested(lowercase__       ,	lowercase__       ,	num_proc=lowercase__       ) == expected_map_nested_sa
          assert map_nested(lowercase__       ,	lowercase__       ,	num_proc=lowercase__       ) == expected_map_nested_sa
          assert map_nested(lowercase__       ,	lowercase__       ,	num_proc=lowercase__       ) == expected_map_nested_sa
          assert map_nested(lowercase__       ,	lowercase__       ,	num_proc=lowercase__       ) == expected_map_nested_sa







'''simple docstring'''


from .testing import (
    are_the_same_tensors,
    execute_subprocess_async,
    require_bnb,
    require_cpu,
    require_cuda,
    require_huggingface_suite,
    require_mps,
    require_multi_gpu,
    require_multi_xpu,
    require_safetensors,
    require_single_gpu,
    require_single_xpu,
    require_torch_min_version,
    require_tpu,
    require_xpu,
    skip,
    slow,
)
from .training import RegressionDataset, RegressionModel, RegressionModelaXPU


from .scripts import test_script, test_sync, test_ops  # isort: skip


