

import textwrap

import pyarrow as pa
import pytest

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






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






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






@pytest.fixture
def    __lowercase (       _A     )       ->  List[str]:
      SCREAMING_SNAKE_CASE	: Optional[int]					       =				tmp_path / """file_with_list_of_dicts.json"""
      SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				textwrap.dedent(
          """\
        [
            {\"col_1\": -1},
            {\"col_1\": 1, \"col_2\": 2},
            {\"col_1\": 10, \"col_2\": 20}
        ]
        """     )
      with open(_A  ,      """w"""     ) as f:
            f.write(_A     )
      return str(_A     )






@pytest.fixture
def    __lowercase (       _A     )       ->  Union[str, Any]:
      SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				tmp_path / """file_with_list_of_dicts_field.json"""
      SCREAMING_SNAKE_CASE	: List[Any]					       =				textwrap.dedent(
          """\
        {
            \"field1\": 1,
            \"field2\": \"aabb\",
            \"field3\": [
                {\"col_1\": -1},
                {\"col_1\": 1, \"col_2\": 2},
                {\"col_1\": 10, \"col_2\": 20}
            ]
        }
        """     )
      with open(_A  ,      """w"""     ) as f:
            f.write(_A     )
      return str(_A     )






@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    __lowercase (       _A  ,      _A  ,      _A     )       ->  Union[str, Any]:
      SCREAMING_SNAKE_CASE	: Any					       =				Json(**_A     )
      SCREAMING_SNAKE_CASE	: Tuple					       =				json._generate_tables([[request.getfixturevalue(_A     )]]     )
      SCREAMING_SNAKE_CASE	: int					       =				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    __lowercase (       _A  ,      _A  ,      _A     )       ->  Any:
      SCREAMING_SNAKE_CASE	: Dict					       =				Json(**_A     )
      SCREAMING_SNAKE_CASE	: Tuple					       =				json._generate_tables([[request.getfixturevalue(_A     )]]     )
      SCREAMING_SNAKE_CASE	: 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], "missing_col": [None, None, None]}







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


UpperCAmelCase__	:       int			      =      {
    """configuration_speech_to_text_2""": ["""SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP""", """Speech2Text2Config"""],
    """processing_speech_to_text_2""": ["""Speech2Text2Processor"""],
    """tokenization_speech_to_text_2""": ["""Speech2Text2Tokenizer"""],
}


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__	:       int			      =      [
      """SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """Speech2Text2ForCausalLM""",
      """Speech2Text2PreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
  from .processing_speech_to_text_a import SpeechaTextaProcessor
  from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_speech_to_text_a import (
        SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
        SpeechaTextaForCausalLM,
        SpeechaTextaPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase__	:       int			      =      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




