

"""simple docstring"""






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       snake_case__  ( datasets.BuilderConfig     ):
			SCREAMING_SNAKE_CASE__     				=						None







class       snake_case__  ( datasets.ArrowBasedBuilder     ):
			SCREAMING_SNAKE_CASE__     				=						PandasConfig







			def 			__lowerCAmelCase				(			self			: str  ):





								'''simple docstring'''



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







			def 			__lowerCAmelCase				(			self			: Optional[Any]			,  lowercase			: str  ):





								'''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}"""  )
								UpperCAmelCase			:   Any      =				dl_manager.download_and_extract(self.config.data_files  )
								if isinstance(lowercase			,  (str, list, tuple)  ):
													UpperCAmelCase			:   str      =				data_files
													if isinstance(lowercase			,  lowercase  ):
																		UpperCAmelCase			:   Dict      =				[files]
													# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
													UpperCAmelCase			:   str      =				[dl_manager.iter_files(lowercase  ) for file in files]
													return [datasets.SplitGenerator(name=datasets.Split.TRAIN			,  gen_kwargs={"files": files}  )]
								UpperCAmelCase			:   Any      =				[]
								for split_name, files in data_files.items():
													if isinstance(lowercase			,  lowercase  ):
																		UpperCAmelCase			:   str      =				[files]
													# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
													UpperCAmelCase			:   Optional[int]      =				[dl_manager.iter_files(lowercase  ) for file in files]
													splits.append(datasets.SplitGenerator(name=lowercase			,  gen_kwargs={"files": files}  )  )
								return splits







			def 			__lowerCAmelCase				(			self			: str			,  lowercase			: pa.Table  ):





								'''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
													UpperCAmelCase			:   Optional[Any]      =				table_cast(lowercase			,  self.config.features.arrow_schema  )
								return pa_table







			def 			__lowerCAmelCase				(			self			: Tuple			,  lowercase			: Dict  ):





								'''simple docstring'''



								for i, file in enumerate(itertools.chain.from_iterable(lowercase  )  ):
													with open(lowercase			,  "rb"  ) as f:
																		UpperCAmelCase			:   Optional[int]      =				pa.Table.from_pandas(pd.read_pickle(lowercase  )  )
																		yield i, self._cast_table(lowercase  )





"""simple docstring"""






def   lowercase_	(    _lowercase       :		list							,      _lowercase       :		int							,      _lowercase       :		int = 0							,      _lowercase       :		int = 0	):




					'''simple docstring'''






					UpperCAmelCase			:   Tuple      =				right or len(_lowercase	) - 1
					if left > right:
										return -1
					elif list_data[left] == key:
										return left
					elif list_data[right] == key:
										return right
					else:
										return search(_lowercase							,      _lowercase							,      left + 1							,      right - 1	)


if __name__ == "__main__":
	import doctest

	doctest.testmod()


