




import textwrap

import pyarrow as pa
import pytest

from datasets import Features, Value
from datasets.packaged_modules.json.json import Json
@pytest.fixture
def  snake_case_					(		SCREAMING_SNAKE_CASE_    )      ->			Any:
							lowercase__  :	Optional[Any]        =							tmp_path / "file.jsonl"
							lowercase__  :	Dict        =							textwrap.dedent(
							    "\\n        {\"col_1\": -1}\n        {\"col_1\": 1, \"col_2\": 2}\n        {\"col_1\": 10, \"col_2\": 20}\n        "    )
							with open(SCREAMING_SNAKE_CASE_    ,"w"    ) as f:
														f.write(SCREAMING_SNAKE_CASE_    )
							return str(SCREAMING_SNAKE_CASE_    )
@pytest.fixture
def  snake_case_					(		SCREAMING_SNAKE_CASE_    )      ->			List[str]:
							lowercase__  :	Any        =							tmp_path / "file_utf16_encoded.jsonl"
							lowercase__  :	Dict        =							textwrap.dedent(
							    "\\n        {\"col_1\": -1}\n        {\"col_1\": 1, \"col_2\": 2}\n        {\"col_1\": 10, \"col_2\": 20}\n        "    )
							with open(SCREAMING_SNAKE_CASE_    ,"w"    ,encoding="utf-16"    ) as f:
														f.write(SCREAMING_SNAKE_CASE_    )
							return str(SCREAMING_SNAKE_CASE_    )
@pytest.fixture
def  snake_case_					(		SCREAMING_SNAKE_CASE_    )      ->			str:
							lowercase__  :	Dict        =							tmp_path / "file_with_list_of_dicts.json"
							lowercase__  :	Union[str, Any]        =							textwrap.dedent(
							    "\\n        [\n            {\"col_1\": -1},\n            {\"col_1\": 1, \"col_2\": 2},\n            {\"col_1\": 10, \"col_2\": 20}\n        ]\n        "    )
							with open(SCREAMING_SNAKE_CASE_    ,"w"    ) as f:
														f.write(SCREAMING_SNAKE_CASE_    )
							return str(SCREAMING_SNAKE_CASE_    )
@pytest.fixture
def  snake_case_					(		SCREAMING_SNAKE_CASE_    )      ->			List[Any]:
							lowercase__  :	Optional[Any]        =							tmp_path / "file_with_list_of_dicts_field.json"
							lowercase__  :	str        =							textwrap.dedent(
							    "\\n        {\n            \"field1\": 1,\n            \"field2\": \"aabb\",\n            \"field3\": [\n                {\"col_1\": -1},\n                {\"col_1\": 1, \"col_2\": 2},\n                {\"col_1\": 10, \"col_2\": 20}\n            ]\n        }\n        "    )
							with open(SCREAMING_SNAKE_CASE_    ,"w"    ) as f:
														f.write(SCREAMING_SNAKE_CASE_    )
							return str(SCREAMING_SNAKE_CASE_    )
@pytest.mark.parametrize(
    "file_fixture, config_kwargs"    ,[
        ("jsonl_file", {}),
        ("jsonl_file_utf16_encoded", {"encoding": "utf-16"}),
        ("json_file_with_list_of_dicts", {}),
        ("json_file_with_list_of_dicts_field", {"field": "field3"}),
    ]    ,)
def  snake_case_					(		SCREAMING_SNAKE_CASE_    ,SCREAMING_SNAKE_CASE_    ,SCREAMING_SNAKE_CASE_    )      ->			Any:
							lowercase__  :	Optional[Any]        =							Json(**SCREAMING_SNAKE_CASE_    )
							lowercase__  :	List[Any]        =							json._generate_tables([[request.getfixturevalue(SCREAMING_SNAKE_CASE_    )]]    )
							lowercase__  :	List[Any]        =							pa.concat_tables([table for _, table in generator]    )
							assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20]}




@pytest.mark.parametrize(
    "file_fixture, config_kwargs"    ,[
        (
            "jsonl_file",
            {"features": Features({"col_1": Value("int64"    ), "col_2": Value("int64"    ), "missing_col": Value("string"    )}    )},
        ),
        (
            "json_file_with_list_of_dicts",
            {"features": Features({"col_1": Value("int64"    ), "col_2": Value("int64"    ), "missing_col": Value("string"    )}    )},
        ),
        (
            "json_file_with_list_of_dicts_field",
            {
                "field": "field3",
                "features": Features(
                    {"col_1": Value("int64"    ), "col_2": Value("int64"    ), "missing_col": Value("string"    )}    ),
            },
        ),
    ]    ,)
def  snake_case_					(		SCREAMING_SNAKE_CASE_    ,SCREAMING_SNAKE_CASE_    ,SCREAMING_SNAKE_CASE_    )      ->			Optional[Any]:
							lowercase__  :	Any        =							Json(**SCREAMING_SNAKE_CASE_    )
							lowercase__  :	int        =							json._generate_tables([[request.getfixturevalue(SCREAMING_SNAKE_CASE_    )]]    )
							lowercase__  :	Tuple        =							pa.concat_tables([table for _, table in generator]    )
							assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20], "missing_col": [None, None, None]}





def  snake_case_					(		SCREAMING_SNAKE_CASE_    )      ->			list:
							lowercase__  :	Optional[Any]        =							len(SCREAMING_SNAKE_CASE_    )

							# Set the gap value to be decreased by a factor of 1.3
							# after each iteration
							lowercase__  :	Tuple        =							1.3

							# Continue sorting until the gap is 1
							while gap > 1:
														# Decrease the gap value
														lowercase__  :	Tuple        =							int(gap / shrink    )

														# Sort the elements using insertion sort
														for i in range(SCREAMING_SNAKE_CASE_    ,len(SCREAMING_SNAKE_CASE_    )    ):
																					lowercase__  :	int        =							collection[i]
																					lowercase__  :	Union[str, Any]        =							i
																					while j >= gap and collection[j - gap] > temp:
																												lowercase__  :	str        =							collection[j - gap]
																												j -= gap
																					lowercase__  :	List[Any]        =							temp

							return collection


if __name__ == "__main__":
						import doctest

						doctest.testmod()