




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


UpperCamelCase__       				=	datasets.utils.logging.get_logger(__name__)
@dataclass
class 							__lowercase   (			datasets.BuilderConfig    ):
     _lowerCAmelCase		       =						None
     _lowerCAmelCase		       =						None
     _lowerCAmelCase		       =						None
     _lowerCAmelCase		       =						True
     _lowerCAmelCase		       =						None
     _lowerCAmelCase		       =						None
     _lowerCAmelCase		       =						None
     _lowerCAmelCase		       =						1_00_00
     _lowerCAmelCase		       =						None



     def 				__magic_name__		(  self   :							Dict       ):





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



     def 				__magic_name__		(  self   :							Tuple      ,		lowercase__   :							List[str]      ,		lowercase__   :							Union[str, Any] = None      ,		):
       a_		    =  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
       a_		    =  config_kwargs['''sql''']
       if not isinstance(snake_case__      ,		snake_case__       ):
         if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
           import sqlalchemy

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

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



     @property
     def 				__magic_name__		(  self   :							List[Any]       ):
       a_		    =  {
           '''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 							__lowercase   (			datasets.ArrowBasedBuilder    ):
     _lowerCAmelCase		       =						SqlConfig



     def 				__magic_name__		(  self   :							List[Any]       ):
       return datasets.DatasetInfo(features=self.config.features       )



     def 				__magic_name__		(  self   :							Dict      ,		lowercase__   :							Optional[Any]       ):
       return [datasets.SplitGenerator(name=datasets.Split.TRAIN      ,		gen_kwargs={}       )]



     def 				__magic_name__		(  self   :							str      ,		lowercase__   :							Tuple       ):





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



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

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


__snake_case         =     {
    '''configuration_mobilevitv2''': [
        '''MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''MobileViTV2Config''',
        '''MobileViTV2OnnxConfig''',
    ],
}


try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __snake_case         =     [
         '''MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''MobileViTV2ForImageClassification''',
         '''MobileViTV2ForSemanticSegmentation''',
         '''MobileViTV2Model''',
         '''MobileViTV2PreTrainedModel''',
     ]

if TYPE_CHECKING:
     from .configuration_mobilevitva import (
         MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
         MobileViTVaConfig,
         MobileViTVaOnnxConfig,
     )

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_mobilevitva import (
              MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
              MobileViTVaForImageClassification,
              MobileViTVaForSemanticSegmentation,
              MobileViTVaModel,
              MobileViTVaPreTrainedModel,
          )

else:
     import sys

     __snake_case         =     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
