




import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, 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


if TYPE_CHECKING:
				import sqlitea

				import sqlalchemy


__a			:	List[str]							     =		datasets.utils.logging.get_logger(__name__)




@dataclass
class     A					(				datasets.BuilderConfig       ):
							_SCREAMING_SNAKE_CASE  :		Union[str, "sqlalchemy.sql.Selectable"]			  =       None
							_SCREAMING_SNAKE_CASE  :		Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]			  =       None
							_SCREAMING_SNAKE_CASE  :		Optional[Union[str, List[str]]]			  =       None
							_SCREAMING_SNAKE_CASE  :		bool			  =       True
							_SCREAMING_SNAKE_CASE  :		Optional[Union[List, Tuple, Dict]]			  =       None
							_SCREAMING_SNAKE_CASE  :		Optional[Union[List, Dict]]			  =       None
							_SCREAMING_SNAKE_CASE  :		Optional[List[str]]			  =       None
							_SCREAMING_SNAKE_CASE  :		Optional[int]			  =       1_00_00
							_SCREAMING_SNAKE_CASE  :		Optional[datasets.Features]			  =       None







							def        lowercase__							(    self   :	str				)		->					List[str]:

										"""simple docstring"""



										if self.sql is None:
													raise ValueError('sql must be specified'				)
										if self.con is None:
													raise ValueError('con must be specified'				)







							def        lowercase__							(    self   :	Union[str, Any]   ,     __UpperCAmelCase   :	dict   ,     __UpperCAmelCase   :	Optional[datasets.Features] = None   ,     )		->					str:

										"""simple docstring"""



										UpperCamelCase_     				= config_kwargs.copy()
										# We need to stringify the Selectable object to make its hash deterministic

										# The process of stringifying is explained here: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html
										UpperCamelCase_     				= config_kwargs['sql']
										if not isinstance(__UpperCAmelCase   ,     __UpperCAmelCase				):
													if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
																import sqlalchemy

																if isinstance(__UpperCAmelCase   ,     sqlalchemy.sql.Selectable				):
																			UpperCamelCase_     				= sqlalchemy.create_engine(config_kwargs['con'].split('://'				)[0] + '://'				)
																			UpperCamelCase_     				= str(sql.compile(dialect=engine.dialect				)				)
																			UpperCamelCase_     				= sql_str
																else:
																			raise TypeError(
																			    f'''Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(__UpperCAmelCase				)}: {sql}'''				)
													else:
																raise TypeError(
																    f'''Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(__UpperCAmelCase				)}: {sql}'''				)
										UpperCamelCase_     				= config_kwargs['con']
										if not isinstance(__UpperCAmelCase   ,     __UpperCAmelCase				):
													UpperCamelCase_     				= id(__UpperCAmelCase				)
													logger.info(
													    f'''SQL connection \'con\' of type {type(__UpperCAmelCase				)} couldn\'t be hashed properly. To enable hashing, specify \'con\' as URI string instead.'''				)

										return super().create_config_id(__UpperCAmelCase   ,     custom_features=__UpperCAmelCase				)







							@property
							def        lowercase__							(    self   :	Optional[Any]				)		->					Union[str, Any]:

										"""simple docstring"""



										UpperCamelCase_     				= {
										    'index_col': self.index_col,
										    'columns': self.columns,
										    'params': self.params,
										    'coerce_float': self.coerce_float,
										    'parse_dates': self.parse_dates,
										}
										return pd_read_sql_kwargs







class     A					(				datasets.ArrowBasedBuilder       ):
							_SCREAMING_SNAKE_CASE  :		Tuple			  =       SqlConfig







							def        lowercase__							(    self   :	str				)		->					Optional[Any]:

										"""simple docstring"""



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







							def        lowercase__							(    self   :	Any   ,     __UpperCAmelCase   :	Dict				)		->					List[Any]:

										"""simple docstring"""



										return [datasets.SplitGenerator(name=datasets.Split.TRAIN   ,     gen_kwargs={}				)]







							def        lowercase__							(    self   :	Dict   ,     __UpperCAmelCase   :	pa.Table				)		->					pa.Table:

										"""simple docstring"""



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







							def        lowercase__							(    self   :	Dict				)		->					Tuple:

										"""simple docstring"""



										UpperCamelCase_     				= self.config.chunksize
										UpperCamelCase_     				= pd.read_sql(
										    self.config.sql   ,     self.config.con   ,     chunksize=__UpperCAmelCase   ,     **self.config.pd_read_sql_kwargs				)
										UpperCamelCase_     				= [sql_reader] if chunksize is None else sql_reader
										for chunk_idx, df in enumerate(__UpperCAmelCase				):
													UpperCamelCase_     				= pa.Table.from_pandas(__UpperCAmelCase				)
													yield chunk_idx, self._cast_table(__UpperCAmelCase				)






from typing import TYPE_CHECKING

from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_tf_available, is_torch_available


__a			:	List[Any]							     =		{
    """configuration_utils""": ["""GenerationConfig"""],
    """streamers""": ["""TextIteratorStreamer""", """TextStreamer"""],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__a			:	Dict							     =		[
				    """Constraint""",
				    """ConstraintListState""",
				    """DisjunctiveConstraint""",
				    """PhrasalConstraint""",
				]
				__a			:	int							     =		[
				    """BeamHypotheses""",
				    """BeamScorer""",
				    """BeamSearchScorer""",
				    """ConstrainedBeamSearchScorer""",
				]
				__a			:	List[Any]							     =		[
				    """EpsilonLogitsWarper""",
				    """EtaLogitsWarper""",
				    """ForcedBOSTokenLogitsProcessor""",
				    """ForcedEOSTokenLogitsProcessor""",
				    """HammingDiversityLogitsProcessor""",
				    """InfNanRemoveLogitsProcessor""",
				    """LogitsProcessor""",
				    """LogitsProcessorList""",
				    """LogitsWarper""",
				    """MinLengthLogitsProcessor""",
				    """MinNewTokensLengthLogitsProcessor""",
				    """NoBadWordsLogitsProcessor""",
				    """NoRepeatNGramLogitsProcessor""",
				    """PrefixConstrainedLogitsProcessor""",
				    """RepetitionPenaltyLogitsProcessor""",
				    """SequenceBiasLogitsProcessor""",
				    """EncoderRepetitionPenaltyLogitsProcessor""",
				    """TemperatureLogitsWarper""",
				    """TopKLogitsWarper""",
				    """TopPLogitsWarper""",
				    """TypicalLogitsWarper""",
				    """EncoderNoRepeatNGramLogitsProcessor""",
				    """ExponentialDecayLengthPenalty""",
				    """LogitNormalization""",
				]
				__a			:	Any							     =		[
				    """MaxNewTokensCriteria""",
				    """MaxLengthCriteria""",
				    """MaxTimeCriteria""",
				    """StoppingCriteria""",
				    """StoppingCriteriaList""",
				    """validate_stopping_criteria""",
				]
				__a			:	str							     =		[
				    """GenerationMixin""",
				    """top_k_top_p_filtering""",
				    """GreedySearchEncoderDecoderOutput""",
				    """GreedySearchDecoderOnlyOutput""",
				    """SampleEncoderDecoderOutput""",
				    """SampleDecoderOnlyOutput""",
				    """BeamSearchEncoderDecoderOutput""",
				    """BeamSearchDecoderOnlyOutput""",
				    """BeamSampleEncoderDecoderOutput""",
				    """BeamSampleDecoderOnlyOutput""",
				    """ContrastiveSearchEncoderDecoderOutput""",
				    """ContrastiveSearchDecoderOnlyOutput""",
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__a			:	List[Any]							     =		[
				    """TFForcedBOSTokenLogitsProcessor""",
				    """TFForcedEOSTokenLogitsProcessor""",
				    """TFLogitsProcessor""",
				    """TFLogitsProcessorList""",
				    """TFLogitsWarper""",
				    """TFMinLengthLogitsProcessor""",
				    """TFNoBadWordsLogitsProcessor""",
				    """TFNoRepeatNGramLogitsProcessor""",
				    """TFRepetitionPenaltyLogitsProcessor""",
				    """TFTemperatureLogitsWarper""",
				    """TFTopKLogitsWarper""",
				    """TFTopPLogitsWarper""",
				    """TFForceTokensLogitsProcessor""",
				    """TFSuppressTokensAtBeginLogitsProcessor""",
				    """TFSuppressTokensLogitsProcessor""",
				]
				__a			:	Any							     =		[
				    """TFGenerationMixin""",
				    """tf_top_k_top_p_filtering""",
				    """TFGreedySearchDecoderOnlyOutput""",
				    """TFGreedySearchEncoderDecoderOutput""",
				    """TFSampleEncoderDecoderOutput""",
				    """TFSampleDecoderOnlyOutput""",
				    """TFBeamSearchEncoderDecoderOutput""",
				    """TFBeamSearchDecoderOnlyOutput""",
				    """TFBeamSampleEncoderDecoderOutput""",
				    """TFBeamSampleDecoderOnlyOutput""",
				    """TFContrastiveSearchEncoderDecoderOutput""",
				    """TFContrastiveSearchDecoderOnlyOutput""",
				]

try:
				if not is_flax_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__a			:	str							     =		[
				    """FlaxForcedBOSTokenLogitsProcessor""",
				    """FlaxForcedEOSTokenLogitsProcessor""",
				    """FlaxLogitsProcessor""",
				    """FlaxLogitsProcessorList""",
				    """FlaxLogitsWarper""",
				    """FlaxMinLengthLogitsProcessor""",
				    """FlaxTemperatureLogitsWarper""",
				    """FlaxTopKLogitsWarper""",
				    """FlaxTopPLogitsWarper""",
				]
				__a			:	Tuple							     =		[
				    """FlaxGenerationMixin""",
				    """FlaxGreedySearchOutput""",
				    """FlaxSampleOutput""",
				    """FlaxBeamSearchOutput""",
				]

if TYPE_CHECKING:
				from .configuration_utils import GenerationConfig
				from .streamers import TextIteratorStreamer, TextStreamer

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint
								from .beam_search import BeamHypotheses, BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
								from .logits_process import (
								    EncoderNoRepeatNGramLogitsProcessor,
								    EncoderRepetitionPenaltyLogitsProcessor,
								    EpsilonLogitsWarper,
								    EtaLogitsWarper,
								    ExponentialDecayLengthPenalty,
								    ForcedBOSTokenLogitsProcessor,
								    ForcedEOSTokenLogitsProcessor,
								    HammingDiversityLogitsProcessor,
								    InfNanRemoveLogitsProcessor,
								    LogitNormalization,
								    LogitsProcessor,
								    LogitsProcessorList,
								    LogitsWarper,
								    MinLengthLogitsProcessor,
								    MinNewTokensLengthLogitsProcessor,
								    NoBadWordsLogitsProcessor,
								    NoRepeatNGramLogitsProcessor,
								    PrefixConstrainedLogitsProcessor,
								    RepetitionPenaltyLogitsProcessor,
								    SequenceBiasLogitsProcessor,
								    TemperatureLogitsWarper,
								    TopKLogitsWarper,
								    TopPLogitsWarper,
								    TypicalLogitsWarper,
								)
								from .stopping_criteria import (
								    MaxLengthCriteria,
								    MaxNewTokensCriteria,
								    MaxTimeCriteria,
								    StoppingCriteria,
								    StoppingCriteriaList,
								    validate_stopping_criteria,
								)
								from .utils import (
								    BeamSampleDecoderOnlyOutput,
								    BeamSampleEncoderDecoderOutput,
								    BeamSearchDecoderOnlyOutput,
								    BeamSearchEncoderDecoderOutput,
								    ContrastiveSearchDecoderOnlyOutput,
								    ContrastiveSearchEncoderDecoderOutput,
								    GenerationMixin,
								    GreedySearchDecoderOnlyOutput,
								    GreedySearchEncoderDecoderOutput,
								    SampleDecoderOnlyOutput,
								    SampleEncoderDecoderOutput,
								    top_k_top_p_filtering,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tf_logits_process import (
								    TFForcedBOSTokenLogitsProcessor,
								    TFForcedEOSTokenLogitsProcessor,
								    TFForceTokensLogitsProcessor,
								    TFLogitsProcessor,
								    TFLogitsProcessorList,
								    TFLogitsWarper,
								    TFMinLengthLogitsProcessor,
								    TFNoBadWordsLogitsProcessor,
								    TFNoRepeatNGramLogitsProcessor,
								    TFRepetitionPenaltyLogitsProcessor,
								    TFSuppressTokensAtBeginLogitsProcessor,
								    TFSuppressTokensLogitsProcessor,
								    TFTemperatureLogitsWarper,
								    TFTopKLogitsWarper,
								    TFTopPLogitsWarper,
								)
								from .tf_utils import (
								    TFBeamSampleDecoderOnlyOutput,
								    TFBeamSampleEncoderDecoderOutput,
								    TFBeamSearchDecoderOnlyOutput,
								    TFBeamSearchEncoderDecoderOutput,
								    TFContrastiveSearchDecoderOnlyOutput,
								    TFContrastiveSearchEncoderDecoderOutput,
								    TFGenerationMixin,
								    TFGreedySearchDecoderOnlyOutput,
								    TFGreedySearchEncoderDecoderOutput,
								    TFSampleDecoderOnlyOutput,
								    TFSampleEncoderDecoderOutput,
								    tf_top_k_top_p_filtering,
								)

				try:
								if not is_flax_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .flax_logits_process import (
								    FlaxForcedBOSTokenLogitsProcessor,
								    FlaxForcedEOSTokenLogitsProcessor,
								    FlaxLogitsProcessor,
								    FlaxLogitsProcessorList,
								    FlaxLogitsWarper,
								    FlaxMinLengthLogitsProcessor,
								    FlaxTemperatureLogitsWarper,
								    FlaxTopKLogitsWarper,
								    FlaxTopPLogitsWarper,
								)
								from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput
else:
				import sys

				__a			:	List[Any]							     =		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
