






"""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       _A    (__a							)				-> Union[str, Any]:  # picklable for multiprocessing
    """simple docstring"""






    return i + 1



@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def       _A    ()				-> Union[str, Any]:
    """simple docstring"""






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

    SCREAMING_SNAKE_CASE_   :						Dict							=	[1, 2, 3]
    with pytest.raises(__a							):
        with parallel_backend('''unsupported backend'''							):
            map_nested(__a					,       __a					,       num_proc=2							)

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





@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('''num_proc'''					,       [2, -1]							)
def       _A    (__a							)				-> Tuple:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						str							=	[1, 2]
    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	{'''a''': 1, '''b''': 2}
    SCREAMING_SNAKE_CASE_   :						List[Any]							=	{'''a''': [1, 2], '''b''': [3, 4]}
    SCREAMING_SNAKE_CASE_   :						Any							=	{'''a''': {'''1''': 1}, '''b''': 2}
    SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	{'''a''': 1, '''b''': 2, '''c''': 3, '''d''': 4}
    SCREAMING_SNAKE_CASE_   :						int							=	[2, 3]
    SCREAMING_SNAKE_CASE_   :						str							=	{'''a''': 2, '''b''': 3}
    SCREAMING_SNAKE_CASE_   :						List[str]							=	{'''a''': [2, 3], '''b''': [4, 5]}
    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	{'''a''': {'''1''': 2}, '''b''': 3}
    SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	{'''a''': 2, '''b''': 3, '''c''': 4, '''d''': 5}

    with parallel_backend('''spark'''							):
        assert map_nested(__a					,       __a					,       num_proc=__a							) == expected_map_nested_sa
        assert map_nested(__a					,       __a					,       num_proc=__a							) == expected_map_nested_sa
        assert map_nested(__a					,       __a					,       num_proc=__a							) == expected_map_nested_sa
        assert map_nested(__a					,       __a					,       num_proc=__a							) == expected_map_nested_sa
        assert map_nested(__a					,       __a					,       num_proc=__a							) == expected_map_nested_sa










"""simple docstring"""






# Algorithm for the pigeonhole sorting





def       _A    (__a							)				-> Dict:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						Dict							=	min(__a							)  # min() finds the minimum value
    SCREAMING_SNAKE_CASE_   :						int							=	max(__a							)  # max() finds the maximum value

    SCREAMING_SNAKE_CASE_   :						Dict							=	max_val - min_val + 1  # size is difference of max and min values plus one

    # list of pigeonholes of size equal to the variable size
    SCREAMING_SNAKE_CASE_   :						Any							=	[0] * size

    # Populate the pigeonholes.
    for x in a:
        assert isinstance(__a					,       __a							), "integers only please"
        holes[x - min_val] += 1

    # Putting the elements back into the array in an order.
    SCREAMING_SNAKE_CASE_   :						Any							=	0
    for count in range(__a							):
        while holes[count] > 0:
            holes[count] -= 1
            SCREAMING_SNAKE_CASE_   :						Dict							=	count + min_val
            i += 1



def       _A    ()				-> Optional[int]:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						List[str]							=	[8, 3, 2, 7, 4, 6, 8]
    pigeonhole_sort(__a							)
    print('''Sorted order is:'''					,       ''' '''.join(__a							)							)


if __name__ == "__main__":
  main()


