




from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__SCREAMING_SNAKE_CASE			:      Dict      			=logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE			:      Optional[int]      			={
    """flaubert/flaubert_small_cased""": """https://huggingface.co/flaubert/flaubert_small_cased/resolve/main/config.json""",
    """flaubert/flaubert_base_uncased""": """https://huggingface.co/flaubert/flaubert_base_uncased/resolve/main/config.json""",
    """flaubert/flaubert_base_cased""": """https://huggingface.co/flaubert/flaubert_base_cased/resolve/main/config.json""",
    """flaubert/flaubert_large_cased""": """https://huggingface.co/flaubert/flaubert_large_cased/resolve/main/config.json""",
}






class 	A	(						_lowerCAmelCase						):
     """simple docstring"""

     _snake_case:		Optional[int]   ="flaubert"
     _snake_case:		Optional[Any]   ={
         "hidden_size": "emb_dim",
         "num_attention_heads": "n_heads",
         "num_hidden_layers": "n_layers",
         "n_words": "vocab_size",  # For backward compatibility
     }




     def __init__(			self     :      Union[str, Any]		,     A__     :      int=False		,     A__     :      str=0.0		,     A__     :      str=3_0_1_4_5		,     A__     :      Union[str, Any]=2_0_4_8		,     A__     :      Dict=1_2		,     A__     :      Dict=1_6		,     A__     :      Dict=0.1		,     A__     :      Any=0.1		,     A__     :      Tuple=True		,     A__     :      List[Any]=False		,     A__     :      Optional[int]=False		,     A__     :      str=False		,     A__     :      Optional[int]=1		,     A__     :      int=True		,     A__     :      Dict=5_1_2		,     A__     :      List[Any]=2_0_4_8**-0.5		,     A__     :      Union[str, Any]=1E-12		,     A__     :      Optional[Any]=0.02		,     A__     :      int=0		,     A__     :      str=1		,     A__     :      List[str]=2		,     A__     :      Dict=3		,     A__     :      List[Any]=5		,     A__     :      Optional[int]=True		,     A__     :      Optional[int]="first"		,     A__     :      Tuple=True		,     A__     :      str=None		,     A__     :      Union[str, Any]=True		,     A__     :      Any=0.1		,     A__     :      Any=5		,     A__     :      Dict=5		,     A__     :      Optional[Any]=0		,     A__     :      Union[str, Any]=0		,     A__     :      str=2		,     A__     :      Union[str, Any]=0		,     **A__     :      int		,     ) ->				Any:
           lowerCamelCase__					     = pre_norm
           lowerCamelCase__					     = layerdrop
           lowerCamelCase__					     = vocab_size
           lowerCamelCase__					     = emb_dim
           lowerCamelCase__					     = n_layers
           lowerCamelCase__					     = n_heads
           lowerCamelCase__					     = dropout
           lowerCamelCase__					     = attention_dropout
           lowerCamelCase__					     = gelu_activation
           lowerCamelCase__					     = sinusoidal_embeddings
           lowerCamelCase__					     = causal
           lowerCamelCase__					     = asm
           lowerCamelCase__					     = n_langs
           lowerCamelCase__					     = use_lang_emb
           lowerCamelCase__					     = layer_norm_eps
           lowerCamelCase__					     = bos_index
           lowerCamelCase__					     = eos_index
           lowerCamelCase__					     = pad_index
           lowerCamelCase__					     = unk_index
           lowerCamelCase__					     = mask_index
           lowerCamelCase__					     = is_encoder
           lowerCamelCase__					     = max_position_embeddings
           lowerCamelCase__					     = embed_init_std
           lowerCamelCase__					     = init_std
           lowerCamelCase__					     = summary_type
           lowerCamelCase__					     = summary_use_proj
           lowerCamelCase__					     = summary_activation
           lowerCamelCase__					     = summary_proj_to_labels
           lowerCamelCase__					     = summary_first_dropout
           lowerCamelCase__					     = start_n_top
           lowerCamelCase__					     = end_n_top
           lowerCamelCase__					     = mask_token_id
           lowerCamelCase__					     = lang_id

           if "n_words" in kwargs:
                 lowerCamelCase__					     = kwargs['n_words']

           super().__init__(pad_token_id=A__		,     bos_token_id=A__		,     **A__	)






class 	A	(						_lowerCAmelCase						):
     """simple docstring"""

     @property
     def        __snake_case      (			self     :      Optional[Any]	) ->				Mapping[str, Mapping[int, str]]:
           if self.task == "multiple-choice":
                 lowerCamelCase__					     = {0: 'batch', 1: 'choice', 2: 'sequence'}
           else:
                 lowerCamelCase__					     = {0: 'batch', 1: 'sequence'}
           return OrderedDict(
               [
                   ('input_ids', dynamic_axis),
                   ('attention_mask', dynamic_axis),
               ]	)





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


__SCREAMING_SNAKE_CASE			:      Union[str, Any]      			=datasets.utils.logging.get_logger(__name__)






@dataclass
class 	A	(						datasets.BuilderConfig						):
     """simple docstring"""

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




     def        __snake_case      (			self     :      Optional[Any]	) ->				Union[str, Any]:
           if self.sql is None:
                 raise ValueError('sql must be specified'	)
           if self.con is None:
                 raise ValueError('con must be specified'	)




     def        __snake_case      (			self     :      List[Any]		,     A__     :      dict		,     A__     :      Optional[datasets.Features] = None		,     ) ->				str:
           lowerCamelCase__					     = 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
           lowerCamelCase__					     = config_kwargs['sql']
           if not isinstance(A__		,     A__	):
                 if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
                       import sqlalchemy

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

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




     @property
     def        __snake_case      (			self     :      Any	) ->				Union[str, Any]:
           lowerCamelCase__					     = {
               '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						):
     """simple docstring"""

     _snake_case:		List[str]   =SqlConfig




     def        __snake_case      (			self     :      Tuple	) ->				Dict:
           return datasets.DatasetInfo(features=self.config.features	)




     def        __snake_case      (			self     :      List[Any]		,     A__     :      Any	) ->				List[Any]:
           return [datasets.SplitGenerator(name=datasets.Split.TRAIN		,     gen_kwargs={}	)]




     def        __snake_case      (			self     :      Union[str, Any]		,     A__     :      pa.Table	) ->				pa.Table:
           if self.config.features is not None:
                 lowerCamelCase__					     = self.config.features.arrow_schema
                 if all(not require_storage_cast(A__	) for feature in self.config.features.values()	):
                       # cheaper cast
                       lowerCamelCase__					     = 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
                       lowerCamelCase__					     = table_cast(A__		,     A__	)
           return pa_table




     def        __snake_case      (			self     :      int	) ->				List[Any]:
           lowerCamelCase__					     = self.config.chunksize
           lowerCamelCase__					     = pd.read_sql(
               self.config.sql		,     self.config.con		,     chunksize=A__		,     **self.config.pd_read_sql_kwargs	)
           lowerCamelCase__					     = [sql_reader] if chunksize is None else sql_reader
           for chunk_idx, df in enumerate(A__	):
                 lowerCamelCase__					     = pa.Table.from_pandas(A__	)
                 yield chunk_idx, self._cast_table(A__	)