






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_	:	str				=				datasets.utils.logging.get_logger(__name__)




@dataclass
class        _lowerCAmelCase( datasets.BuilderConfig      ):





							"""simple docstring"""







							a       :	Union[str, "sqlalchemy.sql.Selectable"]								=None
							a       :	Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]								=None
							a       :	Optional[Union[str, List[str]]]								=None
							a       :	bool								=True
							a       :	Optional[Union[List, Tuple, Dict]]								=None
							a       :	Optional[Union[List, Dict]]								=None
							a       :	Optional[List[str]]								=None
							a       :	Optional[int]								=10000
							a       :	Optional[datasets.Features]								=None





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





							def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase = None						,    ):
									UpperCamelCase_:      List[str]					   =       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_:      int					   =       config_kwargs['sql']
									if not isinstance(_lowerCamelCase						,    _lowerCamelCase							):
											if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
													import sqlalchemy

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

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





							@property
							def     _a					(      self							):
									UpperCamelCase_:      Dict					   =       {
									    '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        _lowerCAmelCase( datasets.ArrowBasedBuilder      ):





							"""simple docstring"""







							a       :	Dict								=SqlConfig





							def     _a					(      self							):
									return datasets.DatasetInfo(features=self.config.features							)





							def     _a					(      self						,    _lowerCamelCase							):
									return [datasets.SplitGenerator(name=datasets.Split.TRAIN						,    gen_kwargs={}							)]





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





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







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A_	:	List[Any]				=				{
    'configuration_openai': ['OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'OpenAIGPTConfig'],
    'tokenization_openai': ['OpenAIGPTTokenizer'],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_	:	List[str]				=				['OpenAIGPTTokenizerFast']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_	:	Any				=				[
       'OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'OpenAIGPTDoubleHeadsModel',
       'OpenAIGPTForSequenceClassification',
       'OpenAIGPTLMHeadModel',
       'OpenAIGPTModel',
       'OpenAIGPTPreTrainedModel',
       'load_tf_weights_in_openai_gpt',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_	:	str				=				[
       'TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'TFOpenAIGPTDoubleHeadsModel',
       'TFOpenAIGPTForSequenceClassification',
       'TFOpenAIGPTLMHeadModel',
       'TFOpenAIGPTMainLayer',
       'TFOpenAIGPTModel',
       'TFOpenAIGPTPreTrainedModel',
   ]


if TYPE_CHECKING:
   from .configuration_openai import OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenAIGPTConfig
   from .tokenization_openai import OpenAIGPTTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_openai_fast import OpenAIGPTTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_openai import (
          OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
          OpenAIGPTDoubleHeadsModel,
          OpenAIGPTForSequenceClassification,
          OpenAIGPTLMHeadModel,
          OpenAIGPTModel,
          OpenAIGPTPreTrainedModel,
          load_tf_weights_in_openai_gpt,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_openai import (
          TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFOpenAIGPTDoubleHeadsModel,
          TFOpenAIGPTForSequenceClassification,
          TFOpenAIGPTLMHeadModel,
          TFOpenAIGPTMainLayer,
          TFOpenAIGPTModel,
          TFOpenAIGPTPreTrainedModel,
      )

else:
   import sys

   A_	:	str				=				_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)