





'''simple docstring'''




from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


__SCREAMING_SNAKE_CASE     :List[Any]       =				logging.get_logger(__name__)


__SCREAMING_SNAKE_CASE     :List[Any]       =				TypeVar('''DatasetType''', Dataset, IterableDataset)
def 	UpperCAmelCase_							(					__lowercase							:      List[DatasetType]			,     __lowercase							:      Optional[List[float]] = None			,     __lowercase							:      Optional[int] = None			,     __lowercase							:      Optional[DatasetInfo] = None			,     __lowercase							:      Optional[NamedSplit] = None			,     __lowercase							:      Literal["first_exhausted", "all_exhausted"] = "first_exhausted"			,     )		->       List[Any]:


     '''simple docstring'''



     from .arrow_dataset import Dataset
     from .iterable_dataset import IterableDataset

     if not datasets:
          raise ValueError("Unable to interleave an empty list of datasets."       )
     for i, dataset in enumerate(__SCREAMING_SNAKE_CASE       ):
          if not isinstance(__SCREAMING_SNAKE_CASE			,     (Dataset, IterableDataset)       ):
               if isinstance(__SCREAMING_SNAKE_CASE			,     (DatasetDict, IterableDatasetDict)       ):
                    if not dataset:
                         raise ValueError(
                             f'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} '
                             "is an empty dataset dictionary."       )
                    raise ValueError(
                        f'Dataset at position {i} has at least one split: {list(__SCREAMING_SNAKE_CASE       )}\n'
                        f'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(__SCREAMING_SNAKE_CASE       )       )}\']'       )
               raise ValueError(
                   f'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__SCREAMING_SNAKE_CASE       ).__name__}.'       )
          if i == 0:
               _UpperCAmelCase     							=   (
                   (Dataset, IterableDataset) if isinstance(__SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE       ) else (IterableDataset, Dataset)
               )
          elif not isinstance(__SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE       ):
               raise ValueError(
                   f'Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects.'       )
     if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
          raise ValueError(f'{stopping_strategy} is not supported. Please enter a valid stopping_strategy.'       )
     if dataset_type is Dataset:
          return _interleave_map_style_datasets(
              __SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE			,     info=__SCREAMING_SNAKE_CASE			,     split=__SCREAMING_SNAKE_CASE			,     stopping_strategy=__SCREAMING_SNAKE_CASE       )
     else:
          return _interleave_iterable_datasets(
              __SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE			,     info=__SCREAMING_SNAKE_CASE			,     split=__SCREAMING_SNAKE_CASE			,     stopping_strategy=__SCREAMING_SNAKE_CASE       )






def 	UpperCAmelCase_							(					__lowercase							:      List[DatasetType]			,     __lowercase							:      Optional[DatasetInfo] = None			,     __lowercase							:      Optional[NamedSplit] = None			,     __lowercase							:      int = 0			,     )		->       str:


     '''simple docstring'''



     if not dsets:
          raise ValueError("Unable to concatenate an empty list of datasets."       )
     for i, dataset in enumerate(__SCREAMING_SNAKE_CASE       ):
          if not isinstance(__SCREAMING_SNAKE_CASE			,     (Dataset, IterableDataset)       ):
               if isinstance(__SCREAMING_SNAKE_CASE			,     (DatasetDict, IterableDatasetDict)       ):
                    if not dataset:
                         raise ValueError(
                             f'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} '
                             "is an empty dataset dictionary."       )
                    raise ValueError(
                        f'Dataset at position {i} has at least one split: {list(__SCREAMING_SNAKE_CASE       )}\n'
                        f'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(__SCREAMING_SNAKE_CASE       )       )}\']'       )
               raise ValueError(
                   f'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__SCREAMING_SNAKE_CASE       ).__name__}.'       )
          if i == 0:
               _UpperCAmelCase     							=   (
                   (Dataset, IterableDataset) if isinstance(__SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE       ) else (IterableDataset, Dataset)
               )
          elif not isinstance(__SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE       ):
               raise ValueError(
                   f'Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects.'       )
     if dataset_type is Dataset:
          return _concatenate_map_style_datasets(__SCREAMING_SNAKE_CASE			,     info=__SCREAMING_SNAKE_CASE			,     split=__SCREAMING_SNAKE_CASE			,     axis=__SCREAMING_SNAKE_CASE       )
     else:
          return _concatenate_iterable_datasets(__SCREAMING_SNAKE_CASE			,     info=__SCREAMING_SNAKE_CASE			,     split=__SCREAMING_SNAKE_CASE			,     axis=__SCREAMING_SNAKE_CASE       )





"""simple docstring"""







import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

__SCREAMING_SNAKE_CASE    	="python tqdm regex requests packaging filelock numpy tokenizers".split()
if sys.version_info < (3, 7):
       pkgs_to_check_at_runtime.append("dataclasses")
if sys.version_info < (3, 8):
       pkgs_to_check_at_runtime.append("importlib_metadata")

for pkg in pkgs_to_check_at_runtime:
       if pkg in deps:
              if pkg == "tokenizers":
                     # must be loaded here, or else tqdm check may fail
                     from .utils import is_tokenizers_available

                     if not is_tokenizers_available():
                            continue  # not required, check version only if installed

              require_version_core(deps[pkg])
       else:
              raise ValueError(F"can't find {pkg} in {deps.keys()}, check dependency_versions_table.py")



def 			lowercase__(       __SCREAMING_SNAKE_CASE							:     int     ,			__SCREAMING_SNAKE_CASE							:     Union[str, Any]=None      ):
     require_version(deps[pkg]     ,			__SCREAMING_SNAKE_CASE      )

