
import textwrap

import pyarrow as pa
import pytest

from datasets import Features, Value
from datasets.packaged_modules.json.json import Json





@pytest.fixture
def    _a (						lowerCamelCase							):
 lowerCamelCase		:     Dict          =				tmp_path / """file.jsonl"""
 lowerCamelCase		:     Tuple          =				textwrap.dedent(
     """\
        {\"col_1\": -1}
        {\"col_1\": 1, \"col_2\": 2}
        {\"col_1\": 10, \"col_2\": 20}
        """							)
 with open(lowerCamelCase,     """w"""							) as f:
  f.write(lowerCamelCase							)
 return str(lowerCamelCase							)





@pytest.fixture
def    _a (						lowerCamelCase							):
 lowerCamelCase		:     List[Any]          =				tmp_path / """file_utf16_encoded.jsonl"""
 lowerCamelCase		:     Optional[Any]          =				textwrap.dedent(
     """\
        {\"col_1\": -1}
        {\"col_1\": 1, \"col_2\": 2}
        {\"col_1\": 10, \"col_2\": 20}
        """							)
 with open(lowerCamelCase,     """w""",     encoding="""utf-16"""							) as f:
  f.write(lowerCamelCase							)
 return str(lowerCamelCase							)





@pytest.fixture
def    _a (						lowerCamelCase							):
 lowerCamelCase		:     Tuple          =				tmp_path / """file_with_list_of_dicts.json"""
 lowerCamelCase		:     Any          =				textwrap.dedent(
     """\
        [
            {\"col_1\": -1},
            {\"col_1\": 1, \"col_2\": 2},
            {\"col_1\": 10, \"col_2\": 20}
        ]
        """							)
 with open(lowerCamelCase,     """w"""							) as f:
  f.write(lowerCamelCase							)
 return str(lowerCamelCase							)





@pytest.fixture
def    _a (						lowerCamelCase							):
 lowerCamelCase		:     Optional[int]          =				tmp_path / """file_with_list_of_dicts_field.json"""
 lowerCamelCase		:     Tuple          =				textwrap.dedent(
     """\
        {
            \"field1\": 1,
            \"field2\": \"aabb\",
            \"field3\": [
                {\"col_1\": -1},
                {\"col_1\": 1, \"col_2\": 2},
                {\"col_1\": 10, \"col_2\": 20}
            ]
        }
        """							)
 with open(lowerCamelCase,     """w"""							) as f:
  f.write(lowerCamelCase							)
 return str(lowerCamelCase							)





@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    _a (						lowerCamelCase,     lowerCamelCase,     lowerCamelCase							):
 lowerCamelCase		:     str          =				Json(**lowerCamelCase							)
 lowerCamelCase		:     Tuple          =				json._generate_tables([[request.getfixturevalue(lowerCamelCase							)]]							)
 lowerCamelCase		:     List[str]          =				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    _a (						lowerCamelCase,     lowerCamelCase,     lowerCamelCase							):
 lowerCamelCase		:     List[Any]          =				Json(**lowerCamelCase							)
 lowerCamelCase		:     Union[str, Any]          =				json._generate_tables([[request.getfixturevalue(lowerCamelCase							)]]							)
 lowerCamelCase		:     str          =				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]}






import sys





def    _a (						lowerCamelCase,     lowerCamelCase							):
 if not numbers:
  return 0
 if target == 0 and target in numbers:
  return 0
 if not isinstance(lowerCamelCase,     (list, tuple)							) or not all(
     isinstance(lowerCamelCase,     lowerCamelCase							) for number in numbers							):
  raise ValueError("""numbers must be an iterable of integers"""							)

 lowerCamelCase		:     str          =				0
 lowerCamelCase		:     List[str]          =				sys.maxsize

 while right < len(lowerCamelCase							):
  curr_sum += numbers[right]
  while curr_sum >= target and left <= right:
   lowerCamelCase		:     Any          =				min(lowerCamelCase,     right - left + 1							)
   curr_sum -= numbers[left]
   left += 1
  right += 1

 return 0 if min_len == sys.maxsize else min_len




