



'''simple docstring'''




import contextlib
import os
import sqlitea

import pytest

from datasets import Dataset, Features, Value
from datasets.io.sql import SqlDatasetReader, SqlDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases, require_sqlalchemy



def      a      (			lowerCamelCase__						,				lowerCamelCase__   ):
			'''simple docstring'''





			assert isinstance(lowerCamelCase__						,				lowerCamelCase__   )
			assert dataset.num_rows == 4
			assert dataset.num_columns == 3
			assert dataset.column_names == ["col_1", "col_2", "col_3"]
			for feature, expected_dtype in expected_features.items():
						assert dataset.features[feature].dtype == expected_dtype



@require_sqlalchemy
@pytest.mark.parametrize("""keep_in_memory"""						,				[False, True]   )
def      a      (			lowerCamelCase__						,				lowerCamelCase__						,				lowerCamelCase__						,				lowerCamelCase__   ):
			'''simple docstring'''





			A_     :						List[str]     =					tmp_path / """cache"""
			A_     :						Optional[Any]     =					{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
			with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
						A_     :						List[Any]     =					SqlDatasetReader(
						    """dataset"""						,				"""sqlite:///""" + sqlite_path						,				cache_dir=lowerCamelCase__						,				keep_in_memory=lowerCamelCase__   ).read()
			_check_sql_dataset(lowerCamelCase__						,				lowerCamelCase__   )



@require_sqlalchemy
@pytest.mark.parametrize(
    """features"""						,				[
        None,
        {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""},
        {"""col_1""": """string""", """col_2""": """string""", """col_3""": """string"""},
        {"""col_1""": """int32""", """col_2""": """int32""", """col_3""": """int32"""},
        {"""col_1""": """float32""", """col_2""": """float32""", """col_3""": """float32"""},
    ]						,				)
def      a      (			lowerCamelCase__						,				lowerCamelCase__						,				lowerCamelCase__						,				lowerCamelCase__   ):
			'''simple docstring'''





			A_     :						str     =					tmp_path / """cache"""
			A_     :						int     =					{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
			A_     :						Tuple     =					features.copy() if features else default_expected_features
			A_     :						List[str]     =					(
			    Features({feature: Value(lowerCamelCase__   ) for feature, dtype in features.items()}   ) if features is not None else None
			)
			A_     :						List[str]     =					SqlDatasetReader("""dataset"""						,				"""sqlite:///""" + sqlite_path						,				features=lowerCamelCase__						,				cache_dir=lowerCamelCase__   ).read()
			_check_sql_dataset(lowerCamelCase__						,				lowerCamelCase__   )



def      a      (			lowerCamelCase__   ):
			'''simple docstring'''





			with contextlib.closing(sqlitea.connect(lowerCamelCase__   )   ) as con:
						A_     :						str     =					con.cursor()
						cur.execute("""SELECT * FROM dataset"""   )
						for row in cur:
									yield row



@require_sqlalchemy
def      a      (			lowerCamelCase__						,				lowerCamelCase__						,				lowerCamelCase__   ):
			'''simple docstring'''





			A_     :						int     =					tmp_path / """cache"""
			A_     :						Optional[int]     =					os.path.join(lowerCamelCase__						,				"""tmp.sql"""   )
			A_     :						Tuple     =					SqlDatasetReader("""dataset"""						,				"""sqlite:///""" + sqlite_path						,				cache_dir=lowerCamelCase__   ).read()
			SqlDatasetWriter(lowerCamelCase__						,				"""dataset"""						,				"""sqlite:///""" + output_sqlite_path						,				num_proc=1   ).write()

			A_     :						Dict     =					iter_sql_file(lowerCamelCase__   )
			A_     :						List[str]     =					iter_sql_file(lowerCamelCase__   )

			for rowa, rowa in zip(lowerCamelCase__						,				lowerCamelCase__   ):
						assert rowa == rowa



@require_sqlalchemy
def      a      (			lowerCamelCase__						,				lowerCamelCase__						,				lowerCamelCase__   ):
			'''simple docstring'''





			A_     :						Optional[Any]     =					tmp_path / """cache"""
			A_     :						List[Any]     =					os.path.join(lowerCamelCase__						,				"""tmp.sql"""   )
			A_     :						int     =					SqlDatasetReader("""dataset"""						,				"""sqlite:///""" + sqlite_path						,				cache_dir=lowerCamelCase__   ).read()
			SqlDatasetWriter(lowerCamelCase__						,				"""dataset"""						,				"""sqlite:///""" + output_sqlite_path						,				num_proc=2   ).write()

			A_     :						List[str]     =					iter_sql_file(lowerCamelCase__   )
			A_     :						List[str]     =					iter_sql_file(lowerCamelCase__   )

			for rowa, rowa in zip(lowerCamelCase__						,				lowerCamelCase__   ):
						assert rowa == rowa



@require_sqlalchemy
def      a      (			lowerCamelCase__						,				lowerCamelCase__						,				lowerCamelCase__   ):
			'''simple docstring'''





			A_     :						Tuple     =					tmp_path / """cache"""
			A_     :						int     =					os.path.join(lowerCamelCase__						,				"""tmp.sql"""   )
			A_     :						Optional[Any]     =					SqlDatasetReader("""dataset"""						,				"""sqlite:///""" + sqlite_path						,				cache_dir=lowerCamelCase__   ).read()
			with pytest.raises(lowerCamelCase__   ):
						SqlDatasetWriter(lowerCamelCase__						,				"""dataset"""						,				"""sqlite:///""" + output_sqlite_path						,				num_proc=0   ).write()




'''simple docstring'''




def      a      (			):
			'''simple docstring'''





			A_     :						Optional[int]     =					[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

			A_     :						Dict     =					6
			A_     :						List[Any]     =					1
			A_     :						Optional[Any]     =					19_01

			A_     :						Tuple     =					0

			while year < 20_01:
						day += 7

						if (year % 4 == 0 and year % 1_00 != 0) or (year % 4_00 == 0):
									if day > days_per_month[month - 1] and month != 2:
												month += 1
												A_     :						Optional[Any]     =					day - days_per_month[month - 2]
									elif day > 29 and month == 2:
												month += 1
												A_     :						str     =					day - 29
						else:
									if day > days_per_month[month - 1]:
												month += 1
												A_     :						List[str]     =					day - days_per_month[month - 2]

						if month > 12:
									year += 1
									A_     :						Tuple     =					1

						if year < 20_01 and day == 1:
									sundays += 1
			return sundays


if __name__ == "__main__":
						print(solution())