






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       _SCREAMING_SNAKE_CASE    (			__lowercase :      Tuple     )    ->   List[str]:  # picklable for multiprocessing





    """simple docstring"""

    return i + 1



@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def       _SCREAMING_SNAKE_CASE    (			)    ->   Optional[int]:





    """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       _SCREAMING_SNAKE_CASE    (			__lowercase :      List[str]     )    ->   int:





    """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












def       _SCREAMING_SNAKE_CASE    (			__lowercase :      int     )    ->   list[int]:





    """simple docstring"""

    if length <= 0 or not isinstance(__lowercase      ,					__lowercase     ):
        raise ValueError("""Length must be a positive integer."""     )
    return [n * (2 * n - 1) for n in range(__lowercase     )]


if __name__ == "__main__":
  print(hexagonal_numbers(length=5))
  print(hexagonal_numbers(length=10))




