






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






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



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

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

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



  @property
  def 						A_				(self  :		int   )		->							List[str]:
   __A	:       List[Any]       =	{
       '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				):
  __lowercase    :    Dict						=					SqlConfig



  def 						A_				(self  :		Optional[Any]   )		->							str:
   return datasets.DatasetInfo(features=self.config.features   )



  def 						A_				(self  :		Optional[Any]				,			lowercase_  :		Any   )		->							Tuple:
   return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,			gen_kwargs={}   )]



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



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













"""simple docstring"""


import math




def 				a (     UpperCamelCase_							:				int		)  ->		list[int]:
 if not isinstance(UpperCamelCase_     ,	UpperCamelCase_		):
  __A	:       Any       =	F"Input value of [number={number}] must be an integer"
  raise TypeError(UpperCamelCase_		)
 if number < 1:
  __A	:       int       =	F"Input value of [number={number}] must be a positive integer"
  raise ValueError(UpperCamelCase_		)
 __A	:       Optional[Any]       =	[number]
 while number != 1:
  if number % 2 == 0:
   __A	:       Optional[int]       =	math.floor(math.sqrt(UpperCamelCase_		)		)
  else:
   __A	:       List[str]       =	math.floor(
       math.sqrt(UpperCamelCase_		) * math.sqrt(UpperCamelCase_		) * math.sqrt(UpperCamelCase_		)		)
  sequence.append(UpperCamelCase_		)
 return sequence


if __name__ == "__main__":
   import doctest

   doctest.testmod()





