
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


lowercase__				:				Tuple						=      datasets.utils.logging.get_logger(__name__)






@dataclass
class 							SCREAMING_SNAKE_CASE__     (				datasets.BuilderConfig     ):

							"""simple docstring"""






							_snake_case  		=	None
							_snake_case  		=	None
							_snake_case  		=	None
							_snake_case  		=	True
							_snake_case  		=	None
							_snake_case  		=	None
							_snake_case  		=	None
							_snake_case  		=	10000
							_snake_case  		=	None



							def      A__		(	self      )-> Tuple:





													'''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      A__		(	self  ,						SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_ = 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(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ):
																			if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
																									import sqlalchemy

																									if isinstance(SCREAMING_SNAKE_CASE_  ,						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(SCREAMING_SNAKE_CASE_      )}: {sql}"      )
																			else:
																									raise TypeError(
																									    F"Supported types for 'sql' are string and sqlalchemy.sql.Selectable but got {type(SCREAMING_SNAKE_CASE_      )}: {sql}"      )
													__UpperCamelCase  	=      config_kwargs['''con''']
													if not isinstance(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ):
																			__UpperCamelCase  	=      id(SCREAMING_SNAKE_CASE_      )
																			logger.info(
																			    F"SQL connection 'con' of type {type(SCREAMING_SNAKE_CASE_      )} couldn't be hashed properly. To enable hashing, specify 'con' as URI string instead."      )

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



							@property
							def      A__		(	self      )-> Tuple:





													'''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 							SCREAMING_SNAKE_CASE__     (				datasets.ArrowBasedBuilder     ):

							"""simple docstring"""






							_snake_case  		=	SqlConfig



							def      A__		(	self      )-> Optional[int]:





													'''simple docstring'''






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



							def      A__		(	self  ,						SCREAMING_SNAKE_CASE_      )-> List[Any]:





													'''simple docstring'''






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



							def      A__		(	self  ,						SCREAMING_SNAKE_CASE_      )-> pa.Table:





													'''simple docstring'''






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



							def      A__		(	self      )-> Dict:





													'''simple docstring'''






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











from typing import TYPE_CHECKING

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


snake_case__   :				Dict						=	{
    'configuration_videomae': ['VIDEOMAE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'VideoMAEConfig'],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       snake_case__   :				Any						=	[
           'VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST',
           'VideoMAEForPreTraining',
           'VideoMAEModel',
           'VideoMAEPreTrainedModel',
           'VideoMAEForVideoClassification',
       ]

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       snake_case__   :				str						=	['VideoMAEFeatureExtractor']
       snake_case__   :				Tuple						=	['VideoMAEImageProcessor']

if TYPE_CHECKING:
       from .configuration_videomae import VIDEOMAE_PRETRAINED_CONFIG_ARCHIVE_MAP, VideoMAEConfig

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_videomae import (
                  VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST,
                  VideoMAEForPreTraining,
                  VideoMAEForVideoClassification,
                  VideoMAEModel,
                  VideoMAEPreTrainedModel,
              )

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .feature_extraction_videomae import VideoMAEFeatureExtractor
              from .image_processing_videomae import VideoMAEImageProcessor

else:
       import sys

       snake_case__   :				Optional[Any]						=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





