






"""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 					_UpperCAmelCase       ( datasets.BuilderConfig							):
					SCREAMING_SNAKE_CASE_		:				Optional[datasets.Features]							    =   None





class 					_UpperCAmelCase       ( datasets.ArrowBasedBuilder							):
					SCREAMING_SNAKE_CASE_		:				Dict							    =   PandasConfig




					def   A  (				self     :						int   )  ->  List[Any]:
							return datasets.DatasetInfo(features=self.config.features   )




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




					def   A  (				self     :						List[str]    ,						A     :						pa.Table   )  ->  pa.Table:
							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
									lowercase_ : Tuple							       =   table_cast(A    ,						self.config.features.arrow_schema   )
							return pa_table






					def   A  (				self     :						Optional[Any]    ,						A     :						Tuple   )  ->  Optional[Any]:
							for i, file in enumerate(itertools.chain.from_iterable(A   )   ):
									with open(A    ,						'''rb'''   ) as f:
											lowercase_ : Any							       =   pa.Table.from_pandas(pd.read_pickle(A   )   )
											yield i, self._cast_table(A   )











"""simple docstring"""



from typing import Optional
from urllib.parse import quote

import huggingface_hub as hfh
from packaging import version



def 						lowercase    (				__snake_case				: str		,					__snake_case				: str		,					__snake_case				: Optional[str] = None	):
		if version.parse(hfh.__version__	).release < version.parse('''0.11.0'''	).release:
				# old versions of hfh don't url-encode the file path
				lowercase_ : Union[str, Any]							       =   quote(__snake_case	)
		return hfh.hf_hub_url(__snake_case		,					__snake_case		,					repo_type='''dataset'''		,					revision=__snake_case	)



