


import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast







@dataclass
class 	__lowercase    (datasets.BuilderConfig  ):





							"""simple docstring"""







							_UpperCAmelCase      =						None







class 	__lowercase    (datasets.ArrowBasedBuilder  ):





							"""simple docstring"""







							_UpperCAmelCase      =						PandasConfig






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										return datasets.DatasetInfo(features=self.config.features       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




										if not self.config.data_files:
													raise ValueError(F'''At least one data file must be specified, but got data_files={self.config.data_files}'''       )
										SCREAMING_SNAKE_CASE_		:     str					=					dl_manager.download_and_extract(self.config.data_files       )
										if isinstance(lowerCAmelCase__			,						(str, list, tuple)       ):
													SCREAMING_SNAKE_CASE_		:     int					=					data_files
													if isinstance(lowerCAmelCase__			,						lowerCAmelCase__       ):
																SCREAMING_SNAKE_CASE_		:     int					=					[files]
													# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
													SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					[dl_manager.iter_files(lowerCAmelCase__       ) for file in files]
													return [datasets.SplitGenerator(name=datasets.Split.TRAIN			,						gen_kwargs={'files': files}       )]
										SCREAMING_SNAKE_CASE_		:     Dict					=					[]
										for split_name, files in data_files.items():
													if isinstance(lowerCAmelCase__			,						lowerCAmelCase__       ):
																SCREAMING_SNAKE_CASE_		:     str					=					[files]
													# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
													SCREAMING_SNAKE_CASE_		:     Optional[int]					=					[dl_manager.iter_files(lowerCAmelCase__       ) for file in files]
													splits.append(datasets.SplitGenerator(name=lowerCAmelCase__			,						gen_kwargs={'files': files}       )       )
										return splits






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




										if self.config.features is not None:
													# more expensive cast to support nested features with keys in a different order
													# allows str <-> int/float or str to Audio for example
													SCREAMING_SNAKE_CASE_		:     List[str]					=					table_cast(lowerCAmelCase__			,						self.config.features.arrow_schema       )
										return pa_table






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




										for i, file in enumerate(itertools.chain.from_iterable(lowerCAmelCase__       )       ):
													with open(lowerCAmelCase__			,						'rb'       ) as f:
																SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					pa.Table.from_pandas(pd.read_pickle(lowerCAmelCase__       )       )
																yield i, self._cast_table(lowerCAmelCase__       )








# 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

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


A									=  {'configuration_mra': ['MRA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MraConfig']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		A									=  [
		    'MRA_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'MraForMaskedLM',
		    'MraForMultipleChoice',
		    'MraForQuestionAnswering',
		    'MraForSequenceClassification',
		    'MraForTokenClassification',
		    'MraLayer',
		    'MraModel',
		    'MraPreTrainedModel',
		]


if TYPE_CHECKING:
		from .configuration_mra import MRA_PRETRAINED_CONFIG_ARCHIVE_MAP, MraConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mra import (
				    MRA_PRETRAINED_MODEL_ARCHIVE_LIST,
				    MraForMaskedLM,
				    MraForMultipleChoice,
				    MraForQuestionAnswering,
				    MraForSequenceClassification,
				    MraForTokenClassification,
				    MraLayer,
				    MraModel,
				    MraPreTrainedModel,
				)
else:
		import sys

		A									=  _LazyModule(__name__, globals()['__file__'], _import_structure)
