

import itertools
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast
from datasets.utils.py_utils import Literal


_snake_case  :	int			      =       datasets.utils.logging.get_logger(__name__)

_snake_case  :	str			      =       ['names', 'prefix']
_snake_case  :	List[Any]			      =       ['warn_bad_lines', 'error_bad_lines', 'mangle_dupe_cols']
_snake_case  :	List[Any]			      =       ['encoding_errors', 'on_bad_lines']
_snake_case  :	Optional[int]			      =       ['date_format']

@dataclass
class        a	(datasets.BuilderConfig   ):




							"""simple docstring"""


							__UpperCAmelCase					:							str  						=						","
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							Optional[Union[int, List[int], str]]  						=						"infer"
							__UpperCAmelCase					:							Optional[List[str]]  						=						None
							__UpperCAmelCase					:							Optional[List[str]]  						=						None
							__UpperCAmelCase					:							Optional[Union[int, str, List[int], List[str]]]  						=						None
							__UpperCAmelCase					:							Optional[Union[List[int], List[str]]]  						=						None
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							bool  						=						True
							__UpperCAmelCase					:							Optional[Literal["c", "python", "pyarrow"]]  						=						None
							__UpperCAmelCase					:							Dict[Union[int, str], Callable[[Any], Any]]  						=						None
							__UpperCAmelCase					:							Optional[list]  						=						None
							__UpperCAmelCase					:							Optional[list]  						=						None
							__UpperCAmelCase					:							bool  						=						False
							__UpperCAmelCase					:							Optional[Union[int, List[int]]]  						=						None
							__UpperCAmelCase					:							Optional[int]  						=						None
							__UpperCAmelCase					:							Optional[Union[str, List[str]]]  						=						None
							__UpperCAmelCase					:							bool  						=						True
							__UpperCAmelCase					:							bool  						=						True
							__UpperCAmelCase					:							bool  						=						False
							__UpperCAmelCase					:							bool  						=						True
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							str  						=						"."
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							str  						=						'"'
							__UpperCAmelCase					:							int  						=						0
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							bool  						=						True
							__UpperCAmelCase					:							bool  						=						True
							__UpperCAmelCase					:							int  						=						0
							__UpperCAmelCase					:							bool  						=						True
							__UpperCAmelCase					:							bool  						=						False
							__UpperCAmelCase					:							Optional[str]  						=						None
							__UpperCAmelCase					:							int  						=						1_0000
							__UpperCAmelCase					:							Optional[datasets.Features]  						=						None
							__UpperCAmelCase					:							Optional[str]  						=						"strict"
							__UpperCAmelCase					:							Literal["error", "warn", "skip"]  						=						"error"
							__UpperCAmelCase					:							Optional[str]  						=						None

							def 					__snake_case      (							self :						Optional[int]       )			->					int:
														if self.delimiter is not None:
																					__snake_case	:    Any											=     self.delimiter
														if self.column_names is not None:
																					__snake_case	:    Optional[Any]											=     self.column_names






							@property
							def 					__snake_case      (							self :						Dict       )			->					Optional[Any]:
														__snake_case	:    Tuple											=     {
														    """sep""": self.sep,
														    """header""": self.header,
														    """names""": self.names,
														    """index_col""": self.index_col,
														    """usecols""": self.usecols,
														    """prefix""": self.prefix,
														    """mangle_dupe_cols""": self.mangle_dupe_cols,
														    """engine""": self.engine,
														    """converters""": self.converters,
														    """true_values""": self.true_values,
														    """false_values""": self.false_values,
														    """skipinitialspace""": self.skipinitialspace,
														    """skiprows""": self.skiprows,
														    """nrows""": self.nrows,
														    """na_values""": self.na_values,
														    """keep_default_na""": self.keep_default_na,
														    """na_filter""": self.na_filter,
														    """verbose""": self.verbose,
														    """skip_blank_lines""": self.skip_blank_lines,
														    """thousands""": self.thousands,
														    """decimal""": self.decimal,
														    """lineterminator""": self.lineterminator,
														    """quotechar""": self.quotechar,
														    """quoting""": self.quoting,
														    """escapechar""": self.escapechar,
														    """comment""": self.comment,
														    """encoding""": self.encoding,
														    """dialect""": self.dialect,
														    """error_bad_lines""": self.error_bad_lines,
														    """warn_bad_lines""": self.warn_bad_lines,
														    """skipfooter""": self.skipfooter,
														    """doublequote""": self.doublequote,
														    """memory_map""": self.memory_map,
														    """float_precision""": self.float_precision,
														    """chunksize""": self.chunksize,
														    """encoding_errors""": self.encoding_errors,
														    """on_bad_lines""": self.on_bad_lines,
														    """date_format""": self.date_format,
														}

														# some kwargs must not be passed if they don't have a default value
														# some others are deprecated and we can also not pass them if they are the default value
														for pd_read_csv_parameter in _PANDAS_READ_CSV_NO_DEFAULT_PARAMETERS + _PANDAS_READ_CSV_DEPRECATED_PARAMETERS:
																					if pd_read_csv_kwargs[pd_read_csv_parameter] == getattr(CsvConfig()					,			A__       ):
																												del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 2.0 new arguments
														if not (datasets.config.PANDAS_VERSION.major >= 2):
																					for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_2_0_0_PARAMETERS:
																												del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 1.3 new arguments
														if not (datasets.config.PANDAS_VERSION.major >= 1 and datasets.config.PANDAS_VERSION.minor >= 3):
																					for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_1_3_0_PARAMETERS:
																												del pd_read_csv_kwargs[pd_read_csv_parameter]

														return pd_read_csv_kwargs

class        a	(datasets.ArrowBasedBuilder   ):




							"""simple docstring"""


							__UpperCAmelCase					:							Tuple  						=						CsvConfig

							def 					__snake_case      (							self :						Optional[int]       )			->					str:
														return datasets.DatasetInfo(features=self.config.features       )

							def 					__snake_case      (							self :						int					,			lowerCamelCase :						Optional[int]       )			->					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}'       )
														__snake_case	:    Any											=     dl_manager.download_and_extract(self.config.data_files       )
														if isinstance(A__					,			(str, list, tuple)       ):
																					__snake_case	:    Dict											=     data_files
																					if isinstance(A__					,			A__       ):
																												__snake_case	:    Any											=     [files]
																					__snake_case	:    Dict											=     [dl_manager.iter_files(A__       ) for file in files]
																					return [datasets.SplitGenerator(name=datasets.Split.TRAIN					,			gen_kwargs={"files": files}       )]
														__snake_case	:    List[Any]											=     []
														for split_name, files in data_files.items():
																					if isinstance(A__					,			A__       ):
																												__snake_case	:    Dict											=     [files]
																					__snake_case	:    int											=     [dl_manager.iter_files(A__       ) for file in files]
																					splits.append(datasets.SplitGenerator(name=A__					,			gen_kwargs={"files": files}       )       )
														return splits

							def 					__snake_case      (							self :						Tuple					,			lowerCamelCase :						Optional[Any]       )			->					Tuple:
														if self.config.features is not None:
																					__snake_case	:    List[str]											=     self.config.features.arrow_schema
																					if all(not require_storage_cast(A__       ) for feature in self.config.features.values()       ):
																												# cheaper cast
																												__snake_case	:    Any											=     pa.Table.from_arrays([pa_table[field.name] for field in schema]					,			schema=A__       )
																					else:
																												# more expensive cast; allows str <-> int/float or str to Audio for example
																												__snake_case	:    Optional[int]											=     table_cast(A__					,			A__       )
														return pa_table






							def 					__snake_case      (							self :						List[str]					,			lowerCamelCase :						Any       )			->					int:
														__snake_case	:    Any											=     self.config.features.arrow_schema if self.config.features else None
														# dtype allows reading an int column as str
														__snake_case	:    Optional[int]											=     (
														    {
														        name: dtype.to_pandas_dtype() if not require_storage_cast(A__       ) else object
														        for name, dtype, feature in zip(schema.names					,			schema.types					,			self.config.features.values()       )
														    }
														    if schema is not None
														    else None
														)
														for file_idx, file in enumerate(itertools.chain.from_iterable(A__       )       ):
																					__snake_case	:    Union[str, Any]											=     pd.read_csv(A__					,			iterator=A__					,			dtype=A__					,			**self.config.pd_read_csv_kwargs       )
																					try:
																												for batch_idx, df in enumerate(A__       ):
																																			__snake_case	:    Optional[int]											=     pa.Table.from_pandas(A__       )
																																			# Uncomment for debugging (will print the Arrow table size and elements)
																																			# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
																																			# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
																																			yield (file_idx, batch_idx), self._cast_table(A__       )
																					except ValueError as e:
																												logger.error(F'Failed to read file \'{file}\' with error {type(A__       )}: {e}'       )
																												raise





import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


_snake_case  :	int			      =       {
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

_snake_case  :	Dict			      =       logging.WARNING







def        lowerCAmelCase_  (      ):
							__snake_case	:    Union[str, Any]											=     os.getenv("DATASETS_VERBOSITY"							,			__lowerCamelCase			)
							if env_level_str:
														if env_level_str in log_levels:
																					return log_levels[env_level_str]
														else:
																					logging.getLogger().warning(
																					    F'Unknown option DATASETS_VERBOSITY={env_level_str}, '
																					    F'has to be one of: { ", ".join(log_levels.keys()			) }'			)
							return _default_log_level







def        lowerCAmelCase_  (      ):
							return __name__.split("."			)[0]







def        lowerCAmelCase_  (      ):
							return logging.getLogger(_get_library_name()			)







def        lowerCAmelCase_  (      ):
							# Apply our default configuration to the library root logger.
							__snake_case	:    str											=     _get_library_root_logger()
							library_root_logger.setLevel(_get_default_logging_level()			)







def        lowerCAmelCase_  (      ):
							__snake_case	:    Dict											=     _get_library_root_logger()
							library_root_logger.setLevel(logging.NOTSET			)







def        lowerCAmelCase_  (      __lowerCamelCase = None			):
							if name is None:
														__snake_case	:    Tuple											=     _get_library_name()
							return logging.getLogger(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return _get_library_root_logger().getEffectiveLevel()







def        lowerCAmelCase_  (      __lowerCamelCase			):
							_get_library_root_logger().setLevel(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return set_verbosity(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return set_verbosity(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return set_verbosity(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return set_verbosity(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							__snake_case	:    List[str]											=     False







def        lowerCAmelCase_  (      ):
							__snake_case	:    Tuple											=     True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()

class        a	:




							"""simple docstring"""


							def __init__(							self :						int					,			*lowerCamelCase :						Optional[Any]					,			**lowerCamelCase :						List[str]       )			->					Optional[int]:  # pylint: disable=unused-argument
														__snake_case	:    int											=     args[0] if args else None

							def __iter__(							self :						Dict       )			->					Optional[int]:
														return iter(self._iterator       )

							def __getattr__(							self :						int					,			lowerCamelCase :						Optional[Any]       )			->					List[Any]:

														def empty_fn(*lowerCamelCase :						Optional[int]					,			**lowerCamelCase :						List[Any]       ):  # pylint: disable=unused-argument
																					return

														return empty_fn

							def __enter__(							self :						List[str]       )			->					int:
														return self






							def __exit__(							self :						Dict					,			lowerCamelCase :						Any					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						str       )			->					Dict:
														return
_snake_case  :	Optional[Any]			      =       True

class        a	:




							"""simple docstring"""


							def __call__(							self :						str					,			*lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						Tuple=False					,			**lowerCamelCase :						Union[str, Any]       )			->					Optional[Any]:
														if _tqdm_active and not disable:
																					return tqdm_lib.tqdm(*lowerCamelCase					,			**lowerCamelCase       )
														else:
																					return EmptyTqdm(*lowerCamelCase					,			**lowerCamelCase       )

							def 					__snake_case      (							self :						str					,			*lowerCamelCase :						str					,			**lowerCamelCase :						Tuple       )			->					str:
														__snake_case	:    Optional[Any]											=     None
														if _tqdm_active:
																					return tqdm_lib.tqdm.set_lock(*lowerCamelCase					,			**lowerCamelCase       )






							def 					__snake_case      (							self :						List[Any]       )			->					List[Any]:
														if _tqdm_active:
																					return tqdm_lib.tqdm.get_lock()
_snake_case  :	int			      =       _tqdm_cls()







def        lowerCAmelCase_  (      ):
							global _tqdm_active
							return bool(_tqdm_active			)







def        lowerCAmelCase_  (      ):
							global _tqdm_active
							__snake_case	:    Tuple											=     True







def        lowerCAmelCase_  (      ):
							global _tqdm_active
							__snake_case	:    List[Any]											=     False

