





'''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_  (						__lowerCamelCase : Union[str, Any]			):  # picklable for multiprocessing
   return i + 1
@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 							UpperCAmelCase_  (						):
   with parallel_backend("spark"			):
      assert ParallelBackendConfig.backend_name == "spark"

   lowercase_      :List[Any]         =			[1, 2, 3]
   with pytest.raises(__lowerCamelCase			):
      with parallel_backend("unsupported backend"			):
         map_nested(__lowerCamelCase     ,__lowerCamelCase     ,num_proc=2			)

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


@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize("num_proc"     ,[2, -1]			)
def 							UpperCAmelCase_  (						__lowerCamelCase : List[Any]			):
   lowercase_      :List[Any]         =			[1, 2]
   lowercase_      :str         =			{"a": 1, "b": 2}
   lowercase_      :Optional[Any]         =			{"a": [1, 2], "b": [3, 4]}
   lowercase_      :Tuple         =			{"a": {"1": 1}, "b": 2}
   lowercase_      :Union[str, Any]         =			{"a": 1, "b": 2, "c": 3, "d": 4}
   lowercase_      :str         =			[2, 3]
   lowercase_      :List[Any]         =			{"a": 2, "b": 3}
   lowercase_      :Optional[int]         =			{"a": [2, 3], "b": [4, 5]}
   lowercase_      :List[str]         =			{"a": {"1": 2}, "b": 3}
   lowercase_      :str         =			{"a": 2, "b": 3, "c": 4, "d": 5}

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









'''simple docstring'''


# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase :					Dict 							={
    '''configuration_xmod''': [
        '''XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XmodConfig''',
        '''XmodOnnxConfig''',
    ],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase :					Union[str, Any] 							=[
     '''XMOD_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''XmodForCausalLM''',
     '''XmodForMaskedLM''',
     '''XmodForMultipleChoice''',
     '''XmodForQuestionAnswering''',
     '''XmodForSequenceClassification''',
     '''XmodForTokenClassification''',
     '''XmodModel''',
     '''XmodPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_xmod import XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP, XmodConfig, XmodOnnxConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_xmod import (
      XMOD_PRETRAINED_MODEL_ARCHIVE_LIST,
      XmodForCausalLM,
      XmodForMaskedLM,
      XmodForMultipleChoice,
      XmodForQuestionAnswering,
      XmodForSequenceClassification,
      XmodForTokenClassification,
      XmodModel,
      XmodPreTrainedModel,
  )

else:
 import sys

 lowerCAmelCase :					Optional[Any] 							=_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


