





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


_lowerCAmelCase							:      Dict						=	datasets.utils.logging.get_logger(__name__)


@dataclass
class 					__magic_name__  (							datasets.BuilderConfig							):





     """simple docstring"""



     __UpperCamelCase					    =     None
     __UpperCamelCase					    =     None
     __UpperCamelCase					    =     None
     __UpperCamelCase					    =     True
     __UpperCamelCase					    =     None
     __UpperCamelCase					    =     None
     __UpperCamelCase					    =     None
     __UpperCamelCase					    =     1_00_00
     __UpperCamelCase					    =     None



     def 						SCREAMING_SNAKE_CASE		(							self       :Optional[int]  ):





        '''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 						SCREAMING_SNAKE_CASE		(							self       :Optional[Any]			,      snake_case       :str			,      snake_case       :Dict = None			,      ):





        '''simple docstring'''




        A_					:				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
        A_					:				Union[str, Any]          =			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  ):
                 A_					:				Any          =			sqlalchemy.create_engine(config_kwargs["con"].split("://"  )[0] + "://"  )
                 A_					:				str          =			str(sql.compile(dialect=engine.dialect  )  )
                 A_					:				Dict          =			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}"  )
        A_					:				Dict          =			config_kwargs["con"]
        if not isinstance(__A			,      __A  ):
           A_					:				List[Any]          =			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 						SCREAMING_SNAKE_CASE		(							self       :Any  ):





        '''simple docstring'''




        A_					:				Tuple          =			{
            "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 					__magic_name__  (							datasets.ArrowBasedBuilder							):





     """simple docstring"""



     __UpperCamelCase					    =     SqlConfig



     def 						SCREAMING_SNAKE_CASE		(							self       :int  ):





        '''simple docstring'''




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



     def 						SCREAMING_SNAKE_CASE		(							self       :Any			,      snake_case       :Dict  ):





        '''simple docstring'''




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



     def 						SCREAMING_SNAKE_CASE		(							self       :Tuple			,      snake_case       :List[Any]  ):





        '''simple docstring'''




        if self.config.features is not None:
           A_					:				int          =			self.config.features.arrow_schema
           if all(not require_storage_cast(__A  ) for feature in self.config.features.values()  ):
              # cheaper cast
              A_					:				Dict          =			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
              A_					:				Dict          =			table_cast(__A			,      __A  )
        return pa_table





     def 						SCREAMING_SNAKE_CASE		(							self       :int  ):





        '''simple docstring'''




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







import warnings
from collections.abc import Callable
from typing import Any

import numpy
from matplotlib import pyplot

_lowerCAmelCase							:      Union[str, Any]						=	0.25 + 0.0j
_lowerCAmelCase							:      str						=	-0.4 + 0.6j
_lowerCAmelCase							:      Optional[int]						=	-0.1 + 0.6_5_1j
_lowerCAmelCase							:      Union[str, Any]						=	-2.0
_lowerCAmelCase							:      str						=	56
_lowerCAmelCase							:      Optional[Any]						=	2.0
_lowerCAmelCase							:      Dict						=	666

def      __snake_case						(					_lowerCAmelCase : complex				,				_lowerCAmelCase : numpy.ndarray	) ->						numpy.ndarray:
   return numpy.exp(_lowerCAmelCase	) + c_parameter

def      __snake_case						(					_lowerCAmelCase : complex				,				_lowerCAmelCase : numpy.ndarray	) ->						numpy.ndarray:
   return z_values * z_values + c_parameter

def      __snake_case						(					_lowerCAmelCase : float				,				_lowerCAmelCase : int	) ->						numpy.ndarray:
   A_					:				Tuple          =			numpy.linspace(-window_size				,				_lowerCAmelCase				,				_lowerCAmelCase	)
   A_					:				Optional[int]          =			x.reshape((nb_pixels, 1)	)
   A_					:				str          =			numpy.linspace(-window_size				,				_lowerCAmelCase				,				_lowerCAmelCase	)
   A_					:				Tuple          =			y.reshape((1, nb_pixels)	)
   return x + 1.0j * y

def      __snake_case						(					_lowerCAmelCase : Callable[[Any, numpy.ndarray], numpy.ndarray]				,				_lowerCAmelCase : Any				,				_lowerCAmelCase : int				,				_lowerCAmelCase : numpy.ndarray				,				_lowerCAmelCase : float | None = None				,				) ->						numpy.ndarray:
   A_					:				List[Any]          =			z_a.astype("complex64"	)
   for _ in range(_lowerCAmelCase	):
      A_					:				List[Any]          =			eval_function(_lowerCAmelCase				,				_lowerCAmelCase	)
      if infinity is not None:
         numpy.nan_to_num(_lowerCAmelCase				,				copy=_lowerCAmelCase				,				nan=_lowerCAmelCase	)
         A_					:				List[Any]          =			infinity
   return z_n

def      __snake_case						(					_lowerCAmelCase : str				,				_lowerCAmelCase : Any				,				_lowerCAmelCase : float				,				_lowerCAmelCase : numpy.ndarray				,				) ->						None:
   A_					:				Optional[int]          =			(abs(_lowerCAmelCase	)).transpose()
   A_					:				Optional[int]          =			abs_z_final[::-1, :]
   pyplot.matshow(abs_z_final < escape_radius	)
   pyplot.title(f"Julia set of ${function_label}$, $c={function_params}$"	)
   pyplot.show()

def      __snake_case						(					) ->						None:
   warnings.filterwarnings(
       "ignore"				,				category=_lowerCAmelCase				,				message="overflow encountered in multiply"	)
   warnings.filterwarnings(
       "ignore"				,				category=_lowerCAmelCase				,				message="invalid value encountered in multiply"				,				)
   warnings.filterwarnings(
       "ignore"				,				category=_lowerCAmelCase				,				message="overflow encountered in absolute"	)
   warnings.filterwarnings(
       "ignore"				,				category=_lowerCAmelCase				,				message="overflow encountered in exp"	)


if __name__ == "__main__":
 _lowerCAmelCase							:      List[str]						=	prepare_grid(window_size, nb_pixels)

 ignore_overflow_warnings()  # See file header for explanations

 _lowerCAmelCase							:      str						=	24
 _lowerCAmelCase							:      str						=	2 * abs(c_cauliflower) + 1
 _lowerCAmelCase							:      Optional[Any]						=	iterate_function(
     eval_quadratic_polynomial,
     c_cauliflower,
     nb_iterations,
     z_a,
     infinity=1.1 * escape_radius,
 )
 show_results('''z^2+c''', c_cauliflower, escape_radius, z_final)

 _lowerCAmelCase							:      Optional[int]						=	64
 _lowerCAmelCase							:      List[Any]						=	2 * abs(c_polynomial_a) + 1
 _lowerCAmelCase							:      List[str]						=	iterate_function(
     eval_quadratic_polynomial,
     c_polynomial_a,
     nb_iterations,
     z_a,
     infinity=1.1 * escape_radius,
 )
 show_results('''z^2+c''', c_polynomial_a, escape_radius, z_final)

 _lowerCAmelCase							:      Tuple						=	161
 _lowerCAmelCase							:      int						=	2 * abs(c_polynomial_a) + 1
 _lowerCAmelCase							:      List[Any]						=	iterate_function(
     eval_quadratic_polynomial,
     c_polynomial_a,
     nb_iterations,
     z_a,
     infinity=1.1 * escape_radius,
 )
 show_results('''z^2+c''', c_polynomial_a, escape_radius, z_final)

 _lowerCAmelCase							:      List[str]						=	12
 _lowerCAmelCase							:      str						=	1_0000.0
 _lowerCAmelCase							:      Tuple						=	iterate_function(
     eval_exponential,
     c_exponential,
     nb_iterations,
     z_a + 2,
     infinity=1.0e10,
 )
 show_results('''e^z+c''', c_exponential, escape_radius, z_final)
