

'''simple docstring'''






import os
import textwrap

import pyarrow as pa
import pytest

from datasets import ClassLabel, Features, Image
from datasets.packaged_modules.csv.csv import Csv

from ..utils import require_pil


@pytest.fixture
def 						_A	(       A__ ):






 """simple docstring"""



 __lowercase				    =					tmp_path / '''file.csv'''
 __lowercase				    =					textwrap.dedent(
     '''\
        header1,header2
        1,2
        10,20
        ''' )
 with open(A__	,							'''w''' ) as f:
  f.write(A__ )
 return str(A__ )


@pytest.fixture
def 						_A	(       A__ ):






 """simple docstring"""



 __lowercase				    =					tmp_path / '''malformed_file.csv'''
 __lowercase				    =					textwrap.dedent(
     '''\
        header1,header2
        1,2
        10,20,
        ''' )
 with open(A__	,							'''w''' ) as f:
  f.write(A__ )
 return str(A__ )


@pytest.fixture
def 						_A	(       A__	,							A__ ):






 """simple docstring"""



 __lowercase				    =					tmp_path / '''csv_with_image.csv'''
 __lowercase				    =					textwrap.dedent(
     F"\\n        image\n        {image_file}\n        " )
 with open(A__	,							'''w''' ) as f:
  f.write(A__ )
 return str(A__ )


@pytest.fixture
def 						_A	(       A__ ):






 """simple docstring"""



 __lowercase				    =					tmp_path / '''csv_with_label.csv'''
 __lowercase				    =					textwrap.dedent(
     '''\
        label
        good
        bad
        good
        ''' )
 with open(A__	,							'''w''' ) as f:
  f.write(A__ )
 return str(A__ )


@pytest.fixture
def 						_A	(       A__ ):






 """simple docstring"""



 __lowercase				    =					tmp_path / '''csv_with_int_list.csv'''
 __lowercase				    =					textwrap.dedent(
     '''\
        int_list
        1 2 3
        4 5 6
        7 8 9
        ''' )
 with open(A__	,							'''w''' ) as f:
  f.write(A__ )
 return str(A__ )


def 						_A	(       A__	,							A__	,							A__ ):






 """simple docstring"""



 __lowercase				    =					Csv()
 __lowercase				    =					csv._generate_tables([[csv_file, malformed_csv_file]] )
 with pytest.raises(A__	,							match='''Error tokenizing data''' ):
  for _ in generator:
   pass
 assert any(
     record.levelname == '''ERROR'''
     and '''Failed to read file''' in record.message
     and os.path.basename(A__ ) in record.message
     for record in caplog.records )


@require_pil
def 						_A	(       A__ ):






 """simple docstring"""



 with open(A__	,							encoding='''utf-8''' ) as f:
  __lowercase				    =					f.read().splitlines()[1]
 __lowercase				    =					Csv(encoding='''utf-8'''	,							features=Features({'''image''': Image()} ) )
 __lowercase				    =					csv._generate_tables([[csv_file_with_image]] )
 __lowercase				    =					pa.concat_tables([table for _, table in generator] )
 assert pa_table.schema.field('''image''' ).type == Image()()
 __lowercase				    =					pa_table.to_pydict()['''image''']
 assert generated_content == [{"path": image_file, "bytes": None}]


def 						_A	(       A__ ):






 """simple docstring"""



 with open(A__	,							encoding='''utf-8''' ) as f:
  __lowercase				    =					f.read().splitlines()[1:]
 __lowercase				    =					Csv(encoding='''utf-8'''	,							features=Features({'''label''': ClassLabel(names=['''good''', '''bad'''] )} ) )
 __lowercase				    =					csv._generate_tables([[csv_file_with_label]] )
 __lowercase				    =					pa.concat_tables([table for _, table in generator] )
 assert pa_table.schema.field('''label''' ).type == ClassLabel(names=['''good''', '''bad'''] )()
 __lowercase				    =					pa_table.to_pydict()['''label''']
 assert generated_content == [ClassLabel(names=['''good''', '''bad'''] ).straint(A__ ) for label in labels]






def 						_A	(       A__ ):






 """simple docstring"""



 __lowercase				    =					Csv(encoding='''utf-8'''	,							sep=''','''	,							converters={'''int_list''': lambda A__ : [int(A__ ) for i in x.split()]} )
 __lowercase				    =					csv._generate_tables([[csv_file_with_int_list]] )
 __lowercase				    =					pa.concat_tables([table for _, table in generator] )
 assert pa.types.is_list(pa_table.schema.field('''int_list''' ).type )
 __lowercase				    =					pa_table.to_pydict()['''int_list''']
 assert generated_content == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]




'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__lowerCamelCase									=     {
    '''configuration_whisper''': ['''WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''WhisperConfig''', '''WhisperOnnxConfig'''],
    '''feature_extraction_whisper''': ['''WhisperFeatureExtractor'''],
    '''processing_whisper''': ['''WhisperProcessor'''],
    '''tokenization_whisper''': ['''WhisperTokenizer'''],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __lowerCamelCase									=     ['''WhisperTokenizerFast''']

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __lowerCamelCase									=     [
          '''WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''WhisperForConditionalGeneration''',
          '''WhisperModel''',
          '''WhisperPreTrainedModel''',
          '''WhisperForAudioClassification''',
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __lowerCamelCase									=     [
          '''TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''TFWhisperForConditionalGeneration''',
          '''TFWhisperModel''',
          '''TFWhisperPreTrainedModel''',
      ]

try:
      if not is_flax_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __lowerCamelCase									=     [
          '''FlaxWhisperForConditionalGeneration''',
          '''FlaxWhisperModel''',
          '''FlaxWhisperPreTrainedModel''',
          '''FlaxWhisperForAudioClassification''',
      ]


if TYPE_CHECKING:
      from .configuration_whisper import WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP, WhisperConfig, WhisperOnnxConfig
      from .feature_extraction_whisper import WhisperFeatureExtractor
      from .processing_whisper import WhisperProcessor
      from .tokenization_whisper import WhisperTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_whisper_fast import WhisperTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_whisper import (
                WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
                WhisperForAudioClassification,
                WhisperForConditionalGeneration,
                WhisperModel,
                WhisperPreTrainedModel,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_whisper import (
                TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFWhisperForConditionalGeneration,
                TFWhisperModel,
                TFWhisperPreTrainedModel,
            )

      try:
            if not is_flax_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_flax_whisper import (
                FlaxWhisperForAudioClassification,
                FlaxWhisperForConditionalGeneration,
                FlaxWhisperModel,
                FlaxWhisperPreTrainedModel,
            )

else:
      import sys

      __lowerCamelCase									=     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
