


'''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 __snake_case   ( UpperCAmelCase_		:		List[str]   ,							UpperCAmelCase_		:		Any						):
 assert isinstance(UpperCAmelCase_   ,							UpperCAmelCase_						)
 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 __snake_case   ( UpperCAmelCase_		:		List[str]   ,							UpperCAmelCase_		:		Any   ,							UpperCAmelCase_		:		Tuple   ,							UpperCAmelCase_		:		Optional[Any]						):
 lowerCamelCase_						=    tmp_path / "cache"
 lowerCamelCase_						=    {"col_1": "string", "col_2": "int64", "col_3": "float64"}
 with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
  lowerCamelCase_						=    SqlDatasetReader(
      "dataset"   ,							"sqlite:///" + sqlite_path   ,							cache_dir=UpperCAmelCase_   ,							keep_in_memory=UpperCAmelCase_						).read()
 _check_sql_dataset(UpperCAmelCase_   ,							UpperCAmelCase_						)





@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 __snake_case   ( UpperCAmelCase_		:		int   ,							UpperCAmelCase_		:		Tuple   ,							UpperCAmelCase_		:		Optional[Any]   ,							UpperCAmelCase_		:		int						):
 lowerCamelCase_						=    tmp_path / "cache"
 lowerCamelCase_						=    {"col_1": "string", "col_2": "int64", "col_3": "float64"}
 lowerCamelCase_						=    features.copy() if features else default_expected_features
 lowerCamelCase_						=    (
     Features({feature: Value(UpperCAmelCase_						) for feature, dtype in features.items()}						) if features is not None else None
 )
 lowerCamelCase_						=    SqlDatasetReader("dataset"   ,							"sqlite:///" + sqlite_path   ,							features=UpperCAmelCase_   ,							cache_dir=UpperCAmelCase_						).read()
 _check_sql_dataset(UpperCAmelCase_   ,							UpperCAmelCase_						)





def __snake_case   ( UpperCAmelCase_		:		List[str]						):







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





@require_sqlalchemy
def __snake_case   ( UpperCAmelCase_		:		int   ,							UpperCAmelCase_		:		List[str]   ,							UpperCAmelCase_		:		List[str]						):
 lowerCamelCase_						=    tmp_path / "cache"
 lowerCamelCase_						=    os.path.join(UpperCAmelCase_   ,							"tmp.sql"						)
 lowerCamelCase_						=    SqlDatasetReader("dataset"   ,							"sqlite:///" + sqlite_path   ,							cache_dir=UpperCAmelCase_						).read()
 SqlDatasetWriter(UpperCAmelCase_   ,							"dataset"   ,							"sqlite:///" + output_sqlite_path   ,							num_proc=1						).write()

 lowerCamelCase_						=    iter_sql_file(UpperCAmelCase_						)
 lowerCamelCase_						=    iter_sql_file(UpperCAmelCase_						)

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





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

 lowerCamelCase_						=    iter_sql_file(UpperCAmelCase_						)
 lowerCamelCase_						=    iter_sql_file(UpperCAmelCase_						)

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







@require_sqlalchemy
def __snake_case   ( UpperCAmelCase_		:		int   ,							UpperCAmelCase_		:		Optional[int]   ,							UpperCAmelCase_		:		int						):
 lowerCamelCase_						=    tmp_path / "cache"
 lowerCamelCase_						=    os.path.join(UpperCAmelCase_   ,							"tmp.sql"						)
 lowerCamelCase_						=    SqlDatasetReader("dataset"   ,							"sqlite:///" + sqlite_path   ,							cache_dir=UpperCAmelCase_						).read()
 with pytest.raises(UpperCAmelCase_						):
  SqlDatasetWriter(UpperCAmelCase_   ,							"dataset"   ,							"sqlite:///" + output_sqlite_path   ,							num_proc=0						).write()






__lowercase				      =						[4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
__lowercase				      =						[3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
__lowercase				      =						{
    0: """Sunday""",
    1: """Monday""",
    2: """Tuesday""",
    3: """Wednesday""",
    4: """Thursday""",
    5: """Friday""",
    6: """Saturday""",
}







def 							_lowerCamelCase   (			SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE   ):
      '''simple docstring'''







      assert len(str(SCREAMING_SNAKE_CASE   )   ) > 2, "year should be in YYYY format"
      assert 1 <= month <= 12, "month should be between 1 to 12"
      assert 1 <= day <= 31, "day should be between 1 to 31"

      # Doomsday algorithm:
      A_							       =		year // 100
      A_							       =		(5 * (century % 4) + 2) % 7
      A_							       =		year % 100
      A_							       =		centurian % 12
      A_							       =		(
          (centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor
      ) % 7
      A_							       =		(
          DOOMSDAY_NOT_LEAP[month - 1]
          if (year % 4 != 0) or (centurian == 0 and (year % 400) == 0)
          else DOOMSDAY_LEAP[month - 1]
      )
      A_							       =		(dooms_day + day - day_anchor) % 7
      return WEEK_DAY_NAMES[week_day]


if __name__ == "__main__":
      import doctest

      doctest.testmod()





