


'''simple docstring'''



import textwrap

import pyarrow as pa
import pytest

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



@pytest.fixture
def     UpperCAmelCase__      (			UpperCAmelCase_					:       Optional[Any]							)  ->	Union[str, Any]:
     __lowerCamelCase     :			Optional[Any]              =	tmp_path / 'file.jsonl'
     __lowerCamelCase     :			int              =	textwrap.dedent(
         '\\n        {"col_1": -1}\n        {"col_1": 1, "col_2": 2}\n        {"col_1": 10, "col_2": 20}\n        '							)
     with open(UpperCAmelCase_   ,					'w'							) as f:
          f.write(UpperCAmelCase_							)
     return str(UpperCAmelCase_							)



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



@pytest.fixture
def     UpperCAmelCase__      (			UpperCAmelCase_					:       Union[str, Any]							)  ->	str:
     __lowerCamelCase     :			List[str]              =	tmp_path / 'file_with_list_of_dicts.json'
     __lowerCamelCase     :			int              =	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(UpperCAmelCase_   ,					'w'							) as f:
          f.write(UpperCAmelCase_							)
     return str(UpperCAmelCase_							)



@pytest.fixture
def     UpperCAmelCase__      (			UpperCAmelCase_					:       Optional[int]							)  ->	Tuple:
     __lowerCamelCase     :			int              =	tmp_path / 'file_with_list_of_dicts_field.json'
     __lowerCamelCase     :			Union[str, Any]              =	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(UpperCAmelCase_   ,					'w'							) as f:
          f.write(UpperCAmelCase_							)
     return str(UpperCAmelCase_							)



@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     UpperCAmelCase__      (			UpperCAmelCase_					:       str   ,					UpperCAmelCase_					:       int   ,					UpperCAmelCase_					:       int							)  ->	Any:
     __lowerCamelCase     :			str              =	Json(**UpperCAmelCase_							)
     __lowerCamelCase     :			Dict              =	json._generate_tables([[request.getfixturevalue(UpperCAmelCase_							)]]							)
     __lowerCamelCase     :			Tuple              =	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     UpperCAmelCase__      (			UpperCAmelCase_					:       Union[str, Any]   ,					UpperCAmelCase_					:       List[Any]   ,					UpperCAmelCase_					:       Dict							)  ->	List[Any]:
     __lowerCamelCase     :			List[str]              =	Json(**UpperCAmelCase_							)
     __lowerCamelCase     :			str              =	json._generate_tables([[request.getfixturevalue(UpperCAmelCase_							)]]							)
     __lowerCamelCase     :			Optional[int]              =	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]}










'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_torch_available


A__	:      Optional[Any]				=						{
    """configuration_xlm_prophetnet""": ["""XLM_PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP""", """XLMProphetNetConfig"""],
}

try:
      if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__	:      List[Any]				=						["""XLMProphetNetTokenizer"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__	:      Optional[Any]				=						[
          """XLM_PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """XLMProphetNetDecoder""",
          """XLMProphetNetEncoder""",
          """XLMProphetNetForCausalLM""",
          """XLMProphetNetForConditionalGeneration""",
          """XLMProphetNetModel""",
          """XLMProphetNetPreTrainedModel""",
      ]


if TYPE_CHECKING:
      from .configuration_xlm_prophetnet import XLM_PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMProphetNetConfig

      try:
            if not is_sentencepiece_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_xlm_prophetnet import XLMProphetNetTokenizer

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_xlm_prophetnet import (
                XLM_PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST,
                XLMProphetNetDecoder,
                XLMProphetNetEncoder,
                XLMProphetNetForCausalLM,
                XLMProphetNetForConditionalGeneration,
                XLMProphetNetModel,
                XLMProphetNetPreTrainedModel,
            )

else:
      import sys

      A__	:      List[str]				=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






