



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


__snake_case		:Tuple   	=  logging.get_logger(__name__)


__snake_case		:str   	=  TypeVar('''DatasetType''', Dataset, IterableDataset)





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase = None     ,				_UpperCAmelCase = None     ,				_UpperCAmelCase = None     ,				_UpperCAmelCase = None     ,				_UpperCAmelCase = "first_exhausted"     ,				)     ->   List[str]:
    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(_UpperCAmelCase       ):
        if not isinstance(_UpperCAmelCase     ,				(Dataset, IterableDataset)       ):
            if isinstance(_UpperCAmelCase     ,				(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(_UpperCAmelCase       )}\n'
                    f'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(_UpperCAmelCase       )       )}\']'       )
            raise ValueError(
                f'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(_UpperCAmelCase       ).__name__}.'       )
        if i == 0:
            __a ,     __a		 =       (
                (Dataset, IterableDataset) if isinstance(_UpperCAmelCase     ,				_UpperCAmelCase       ) else (IterableDataset, Dataset)
            )
        elif not isinstance(_UpperCAmelCase     ,				_UpperCAmelCase       ):
            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(
            _UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase     ,				info=_UpperCAmelCase     ,				split=_UpperCAmelCase     ,				stopping_strategy=_UpperCAmelCase       )
    else:
        return _interleave_iterable_datasets(
            _UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase     ,				info=_UpperCAmelCase     ,				split=_UpperCAmelCase     ,				stopping_strategy=_UpperCAmelCase       )





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase = None     ,				_UpperCAmelCase = None     ,				_UpperCAmelCase = 0     ,				)     ->   Optional[int]:

    if not dsets:
        raise ValueError('''Unable to concatenate an empty list of datasets.'''       )
    for i, dataset in enumerate(_UpperCAmelCase       ):
        if not isinstance(_UpperCAmelCase     ,				(Dataset, IterableDataset)       ):
            if isinstance(_UpperCAmelCase     ,				(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(_UpperCAmelCase       )}\n'
                    f'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(_UpperCAmelCase       )       )}\']'       )
            raise ValueError(
                f'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(_UpperCAmelCase       ).__name__}.'       )
        if i == 0:
            __a ,     __a		 =       (
                (Dataset, IterableDataset) if isinstance(_UpperCAmelCase     ,				_UpperCAmelCase       ) else (IterableDataset, Dataset)
            )
        elif not isinstance(_UpperCAmelCase     ,				_UpperCAmelCase       ):
            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(_UpperCAmelCase     ,				info=_UpperCAmelCase     ,				split=_UpperCAmelCase     ,				axis=_UpperCAmelCase       )
    else:
        return _concatenate_iterable_datasets(_UpperCAmelCase     ,				info=_UpperCAmelCase     ,				split=_UpperCAmelCase     ,				axis=_UpperCAmelCase       )










def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase = False       ):

    if not isinstance(_UpperCAmelCase     ,				_UpperCAmelCase       ):
        __a		 =       f'Expected string as input, found {type(_UpperCAmelCase       )}'
        raise ValueError(_UpperCAmelCase       )
    if not isinstance(_UpperCAmelCase     ,				_UpperCAmelCase       ):
        __a		 =       f'Expected boolean as use_pascal parameter, found {type(_UpperCAmelCase       )}'
        raise ValueError(_UpperCAmelCase       )

    __a		 =       input_str.split('''_'''       )

    __a		 =       0 if use_pascal else 1

    __a		 =       words[start_index:]

    __a		 =       [word[0].upper() + word[1:] for word in words_to_capitalize]

    __a		 =       '''''' if use_pascal else words[0]

    return "".join([initial_word, *capitalized_words]       )


if __name__ == "__main__":
 from doctest import testmod

 testmod()





