'''simple docstring'''
import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

import pyarrow as pa
import pyarrow.parquet as pq
import pytest

import datasets
import datasets.config



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      ):


      '''simple docstring'''


      UpperCAmelCase_            =  10
      UpperCAmelCase_            =  datasets.Features(
          {
              '''tokens''': datasets.Sequence(datasets.Value('''string'''					)					),
              '''labels''': datasets.Sequence(datasets.ClassLabel(names=['''negative''', '''positive''']					)					),
              '''answers''': datasets.Sequence(
                  {
                      '''text''': datasets.Value('''string'''					),
                      '''answer_start''': datasets.Value('''int32'''					),
                  }					),
              '''id''': datasets.Value('''int64'''					),
          }					)
      UpperCAmelCase_            =  datasets.Dataset.from_dict(
          {
              '''tokens''': [['''foo'''] * 5] * n,
              '''labels''': [[1] * 5] * n,
              '''answers''': [{'''answer_start''': [97], '''text''': ['''1976''']}] * 10,
              '''id''': list(range(_UpperCamelCase					)					),
          }							,    features=_UpperCamelCase							,    )
      return dataset



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  List[str]							,    _UpperCamelCase  :  Optional[int]					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''file.arrow'''					)
      dataset.map(cache_file_name=_UpperCamelCase					)
      return filename


# FILE_CONTENT + files


lowercase__  :      Tuple        =					"\\n    Text data.\n    Second line of data."



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Tuple					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.txt'''
      UpperCAmelCase_            =  FILE_CONTENT
      with open(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase					)
      return filename



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[Any]					):


      '''simple docstring'''


      import bza

      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.txt.bz2'''
      UpperCAmelCase_            =  bytes(_UpperCamelCase							,    '''utf-8'''					)
      with bza.open(_UpperCamelCase							,    '''wb'''					) as f:
            f.write(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  int					):


      '''simple docstring'''


      import gzip

      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''file.txt.gz'''					)
      UpperCAmelCase_            =  bytes(_UpperCamelCase							,    '''utf-8'''					)
      with gzip.open(_UpperCamelCase							,    '''wb'''					) as f:
            f.write(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Union[str, Any]					):


      '''simple docstring'''


      if datasets.config.LZ4_AVAILABLE:
            import lza.frame

            UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.txt.lz4'''
            UpperCAmelCase_            =  bytes(_UpperCamelCase							,    '''utf-8'''					)
            with lza.frame.open(_UpperCamelCase							,    '''wb'''					) as f:
                  f.write(_UpperCamelCase					)
            return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Any							,    _UpperCamelCase  :  Dict					):


      '''simple docstring'''


      if datasets.config.PY7ZR_AVAILABLE:
            import pyazr

            UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.txt.7z'''
            with pyazr.SevenZipFile(_UpperCamelCase							,    '''w'''					) as archive:
                  archive.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
            return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  List[str]							,    _UpperCamelCase  :  List[Any]					):


      '''simple docstring'''


      import tarfile

      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.txt.tar'''
      with tarfile.TarFile(_UpperCamelCase							,    '''w'''					) as f:
            f.add(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Any					):


      '''simple docstring'''


      import lzma

      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.txt.xz'''
      UpperCAmelCase_            =  bytes(_UpperCamelCase							,    '''utf-8'''					)
      with lzma.open(_UpperCamelCase							,    '''wb'''					) as f:
            f.write(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  str							,    _UpperCamelCase  :  Dict					):


      '''simple docstring'''


      import zipfile

      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.txt.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  int					):


      '''simple docstring'''


      if datasets.config.ZSTANDARD_AVAILABLE:
            import zstandard as zstd

            UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.txt.zst'''
            UpperCAmelCase_            =  bytes(_UpperCamelCase							,    '''utf-8'''					)
            with zstd.open(_UpperCamelCase							,    '''wb'''					) as f:
                  f.write(_UpperCamelCase					)
            return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Dict					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''file.xml'''
      UpperCAmelCase_            =  textwrap.dedent(
          '''\
    <?xml version="1.0" encoding="UTF-8" ?>
    <tmx version="1.4">
      <header segtype="sentence" srclang="ca" />
      <body>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 1</seg></tuv>
          <tuv xml:lang="en"><seg>Content 1</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 2</seg></tuv>
          <tuv xml:lang="en"><seg>Content 2</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 3</seg></tuv>
          <tuv xml:lang="en"><seg>Content 3</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 4</seg></tuv>
          <tuv xml:lang="en"><seg>Content 4</seg></tuv>
        </tu>
        <tu>
          <tuv xml:lang="ca"><seg>Contingut 5</seg></tuv>
          <tuv xml:lang="en"><seg>Content 5</seg></tuv>
        </tu>
      </body>
    </tmx>'''					)
      with open(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase					)
      return filename


lowercase__  :      List[str]        =					[
    {"col_1": "0", "col_2": 0, "col_3": 0.0},
    {"col_1": "1", "col_2": 1, "col_3": 1.0},
    {"col_1": "2", "col_2": 2, "col_3": 2.0},
    {"col_1": "3", "col_2": 3, "col_3": 3.0},
]
lowercase__  :      List[Any]        =					[
    {"col_1": "4", "col_2": 4, "col_3": 4.0},
    {"col_1": "5", "col_2": 5, "col_3": 5.0},
]
lowercase__  :      List[Any]        =					{
    "col_1": ["0", "1", "2", "3"],
    "col_2": [0, 1, 2, 3],
    "col_3": [0.0, 1.0, 2.0, 3.0],
}

lowercase__  :      Optional[int]        =					[
    {"col_3": 0.0, "col_1": "0", "col_2": 0},
    {"col_3": 1.0, "col_1": "1", "col_2": 1},
]

lowercase__  :      List[str]        =					[
    {"col_1": "s0", "col_2": 0, "col_3": 0.0},
    {"col_1": "s1", "col_2": 1, "col_3": 1.0},
    {"col_1": "s2", "col_2": 2, "col_3": 2.0},
    {"col_1": "s3", "col_2": 3, "col_3": 3.0},
]



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      ):


      '''simple docstring'''


      return DATA_DICT_OF_LISTS



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  List[str]					):


      '''simple docstring'''


      UpperCAmelCase_            =  datasets.Dataset.from_dict(_UpperCamelCase					)
      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.arrow'''					)
      dataset.map(cache_file_name=_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Union[str, Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.sqlite'''					)
      with contextlib.closing(sqlitea.connect(_UpperCamelCase					)					) as con:
            UpperCAmelCase_            =  con.cursor()
            cur.execute('''CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)'''					)
            for item in DATA:
                  cur.execute('''INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)'''							,    tuple(item.values()					)					)
            con.commit()
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  List[Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.csv'''					)
      with open(_UpperCamelCase							,    '''w'''							,    newline=''''''					) as f:
            UpperCAmelCase_            =  csv.DictWriter(_UpperCamelCase							,    fieldnames=['''col_1''', '''col_2''', '''col_3''']					)
            writer.writeheader()
            for item in DATA:
                  writer.writerow(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[int]					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset2.csv'''					)
      with open(_UpperCamelCase							,    '''w'''							,    newline=''''''					) as f:
            UpperCAmelCase_            =  csv.DictWriter(_UpperCamelCase							,    fieldnames=['''col_1''', '''col_2''', '''col_3''']					)
            writer.writeheader()
            for item in DATA:
                  writer.writerow(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Any							,    _UpperCamelCase  :  Optional[int]					):


      '''simple docstring'''


      import bza

      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.csv.bz2'''
      with open(_UpperCamelCase							,    '''rb'''					) as f:
            UpperCAmelCase_            =  f.read()
      # data = bytes(FILE_CONTENT, "utf-8")
      with bza.open(_UpperCamelCase							,    '''wb'''					) as f:
            f.write(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[int]							,    _UpperCamelCase  :  Dict							,    _UpperCamelCase  :  List[str]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.csv.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  int							,    _UpperCamelCase  :  Dict							,    _UpperCamelCase  :  str					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.csv.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.basename(csv_path.replace('''.csv'''							,    '''.CSV'''					)					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.basename(csva_path.replace('''.csv'''							,    '''.CSV'''					)					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Any							,    _UpperCamelCase  :  str							,    _UpperCamelCase  :  Tuple					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset_with_dir.csv.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.join('''main_dir'''							,    os.path.basename(_UpperCamelCase					)					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.join('''main_dir'''							,    os.path.basename(_UpperCamelCase					)					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Any					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.parquet'''					)
      UpperCAmelCase_            =  pa.schema(
          {
              '''col_1''': pa.string(),
              '''col_2''': pa.intaa(),
              '''col_3''': pa.floataa(),
          }					)
      with open(_UpperCamelCase							,    '''wb'''					) as f:
            UpperCAmelCase_            =  pq.ParquetWriter(_UpperCamelCase							,    schema=_UpperCamelCase					)
            UpperCAmelCase_            =  pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(_UpperCamelCase					)					)] for k in DATA[0]}							,    schema=_UpperCamelCase					)
            writer.write_table(_UpperCamelCase					)
            writer.close()
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[int]					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.json'''					)
      UpperCAmelCase_            =  {'''data''': DATA}
      with open(_UpperCamelCase							,    '''w'''					) as f:
            json.dump(_UpperCamelCase							,    _UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Union[str, Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.json'''					)
      UpperCAmelCase_            =  {'''data''': DATA_DICT_OF_LISTS}
      with open(_UpperCamelCase							,    '''w'''					) as f:
            json.dump(_UpperCamelCase							,    _UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Tuple					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.jsonl'''					)
      with open(_UpperCamelCase							,    '''w'''					) as f:
            for item in DATA:
                  f.write(json.dumps(_UpperCamelCase					) + '''\n'''					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Union[str, Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset2.jsonl'''					)
      with open(_UpperCamelCase							,    '''w'''					) as f:
            for item in DATA:
                  f.write(json.dumps(_UpperCamelCase					) + '''\n'''					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Dict					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset_312.jsonl'''					)
      with open(_UpperCamelCase							,    '''w'''					) as f:
            for item in DATA_312:
                  f.write(json.dumps(_UpperCamelCase					) + '''\n'''					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Union[str, Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset-str.jsonl'''					)
      with open(_UpperCamelCase							,    '''w'''					) as f:
            for item in DATA_STR:
                  f.write(json.dumps(_UpperCamelCase					) + '''\n'''					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  int							,    _UpperCamelCase  :  Union[str, Any]					):


      '''simple docstring'''


      import gzip

      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.txt.gz'''					)
      with open(_UpperCamelCase							,    '''rb'''					) as orig_file:
            with gzip.open(_UpperCamelCase							,    '''wb'''					) as zipped_file:
                  zipped_file.writelines(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Dict							,    _UpperCamelCase  :  Tuple					):


      '''simple docstring'''


      import gzip

      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.jsonl.gz'''					)
      with open(_UpperCamelCase							,    '''rb'''					) as orig_file:
            with gzip.open(_UpperCamelCase							,    '''wb'''					) as zipped_file:
                  zipped_file.writelines(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  int							,    _UpperCamelCase  :  Tuple							,    _UpperCamelCase  :  Tuple					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.jsonl.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Union[str, Any]							,    _UpperCamelCase  :  Optional[int]							,    _UpperCamelCase  :  int							,    _UpperCamelCase  :  List[Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset_nested.jsonl.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.join('''nested'''							,    os.path.basename(_UpperCamelCase					)					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[int]							,    _UpperCamelCase  :  Optional[Any]							,    _UpperCamelCase  :  Optional[Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset_with_dir.jsonl.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.join('''main_dir'''							,    os.path.basename(_UpperCamelCase					)					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.join('''main_dir'''							,    os.path.basename(_UpperCamelCase					)					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  str							,    _UpperCamelCase  :  str							,    _UpperCamelCase  :  Optional[int]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.jsonl.tar'''
      with tarfile.TarFile(_UpperCamelCase							,    '''w'''					) as f:
            f.add(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
            f.add(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Union[str, Any]							,    _UpperCamelCase  :  str							,    _UpperCamelCase  :  Dict							,    _UpperCamelCase  :  Optional[Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset_nested.jsonl.tar'''
      with tarfile.TarFile(_UpperCamelCase							,    '''w'''					) as f:
            f.add(_UpperCamelCase							,    arcname=os.path.join('''nested'''							,    os.path.basename(_UpperCamelCase					)					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Tuple					):


      '''simple docstring'''


      UpperCAmelCase_            =  ['''0''', '''1''', '''2''', '''3''']
      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset.txt'''					)
      with open(_UpperCamelCase							,    '''w'''					) as f:
            for item in data:
                  f.write(item + '''\n'''					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  ['''0''', '''1''', '''2''', '''3''']
      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset2.txt'''					)
      with open(_UpperCamelCase							,    '''w'''					) as f:
            for item in data:
                  f.write(item + '''\n'''					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Any					):


      '''simple docstring'''


      UpperCAmelCase_            =  ['''0''', '''1''', '''2''', '''3''']
      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.abc'''
      with open(_UpperCamelCase							,    '''w'''					) as f:
            for item in data:
                  f.write(item + '''\n'''					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Dict							,    _UpperCamelCase  :  Union[str, Any]							,    _UpperCamelCase  :  Union[str, Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.text.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[int]							,    _UpperCamelCase  :  Optional[int]							,    _UpperCamelCase  :  Optional[int]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset_with_dir.text.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.join('''main_dir'''							,    os.path.basename(_UpperCamelCase					)					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.join('''main_dir'''							,    os.path.basename(_UpperCamelCase					)					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[Any]							,    _UpperCamelCase  :  Dict							,    _UpperCamelCase  :  Optional[Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.ext.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.basename('''unsupported.ext'''					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.basename('''unsupported_2.ext'''					)					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  str					):


      '''simple docstring'''


      UpperCAmelCase_            =  '''\n'''.join(['''First''', '''Second\u2029with Unicode new line''', '''Third''']					)
      UpperCAmelCase_            =  str(tmp_path_factory.mktemp('''data'''					) / '''dataset_with_unicode_new_lines.txt'''					)
      with open(_UpperCamelCase							,    '''w'''							,    encoding='''utf-8'''					) as f:
            f.write(_UpperCamelCase					)
      return path



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      ):


      '''simple docstring'''


      return os.path.join('''tests'''							,    '''features'''							,    '''data'''							,    '''test_image_rgb.jpg'''					)



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      ):


      '''simple docstring'''


      return os.path.join('''tests'''							,    '''features'''							,    '''data'''							,    '''test_audio_44100.wav'''					)



@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  int							,    _UpperCamelCase  :  Tuple					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data'''					) / '''dataset.img.zip'''
      with zipfile.ZipFile(_UpperCamelCase							,    '''w'''					) as f:
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					)					)
            f.write(_UpperCamelCase							,    arcname=os.path.basename(_UpperCamelCase					).replace('''.jpg'''							,    '''2.jpg'''					)					)
      return path





@pytest.fixture(scope='''session'''					)
def  __lowerCamelCase       (      _UpperCamelCase  :  Optional[Any]					):


      '''simple docstring'''


      UpperCAmelCase_            =  tmp_path_factory.mktemp('''data_dir'''					)

      (data_dir / "subdir").mkdir()
      with open(data_dir / '''subdir''' / '''train.txt'''							,    '''w'''					) as f:
            f.write('''foo\n''' * 10					)
      with open(data_dir / '''subdir''' / '''test.txt'''							,    '''w'''					) as f:
            f.write('''bar\n''' * 10					)
      # hidden file
      with open(data_dir / '''subdir''' / '''.test.txt'''							,    '''w'''					) as f:
            f.write('''bar\n''' * 10					)

      # hidden directory
      (data_dir / ".subdir").mkdir()
      with open(data_dir / '''.subdir''' / '''train.txt'''							,    '''w'''					) as f:
            f.write('''foo\n''' * 10					)
      with open(data_dir / '''.subdir''' / '''test.txt'''							,    '''w'''					) as f:
            f.write('''bar\n''' * 10					)

      return data_dir






'''simple docstring'''
from typing import List, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase__  :      int        =					logging.get_logger(__name__)

lowercase__  :      List[str]        =					{
    "huggingface/time-series-transformer-tourism-monthly": (
        "https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json"
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}







class lowerCamelCase							(	lowerCamelCase					):




  '''simple docstring'''



  lowerCAmelCase__										=	'''time_series_transformer'''
  lowerCAmelCase__										=	{
      '''hidden_size''': '''d_model''',
      '''num_attention_heads''': '''encoder_attention_heads''',
      '''num_hidden_layers''': '''encoder_layers''',
  }






  def __init__(      self			:       Optional[int]  ,							UpperCAmelCase__			:       Optional[int] = None  ,							UpperCAmelCase__			:       Optional[int] = None  ,							UpperCAmelCase__			:       str = "student_t"  ,							UpperCAmelCase__			:       str = "nll"  ,							UpperCAmelCase__			:       int = 1  ,							UpperCAmelCase__			:       List[int] = [1, 2, 3, 4, 5, 6, 7]  ,							UpperCAmelCase__			:       Optional[Union[str, bool]] = "mean"  ,							UpperCAmelCase__			:       int = 0  ,							UpperCAmelCase__			:       int = 0  ,							UpperCAmelCase__			:       int = 0  ,							UpperCAmelCase__			:       int = 0  ,							UpperCAmelCase__			:       Optional[List[int]] = None  ,							UpperCAmelCase__			:       Optional[List[int]] = None  ,							UpperCAmelCase__			:       int = 32  ,							UpperCAmelCase__			:       int = 32  ,							UpperCAmelCase__			:       int = 2  ,							UpperCAmelCase__			:       int = 2  ,							UpperCAmelCase__			:       int = 2  ,							UpperCAmelCase__			:       int = 2  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       str = "gelu"  ,							UpperCAmelCase__			:       int = 64  ,							UpperCAmelCase__			:       float = 0.1  ,							UpperCAmelCase__			:       float = 0.1  ,							UpperCAmelCase__			:       float = 0.1  ,							UpperCAmelCase__			:       float = 0.1  ,							UpperCAmelCase__			:       float = 0.1  ,							UpperCAmelCase__			:       int = 100  ,							UpperCAmelCase__			:       float = 0.02  ,							UpperCAmelCase__			:       Union[str, Any]=True  ,							**UpperCAmelCase__			:       Tuple  ,							)				->Optional[int]:
        # time series specific configuration
        UpperCAmelCase_            =  prediction_length
        UpperCAmelCase_            =  context_length or prediction_length
        UpperCAmelCase_            =  distribution_output
        UpperCAmelCase_            =  loss
        UpperCAmelCase_            =  input_size
        UpperCAmelCase_            =  num_time_features
        UpperCAmelCase_            =  lags_sequence
        UpperCAmelCase_            =  scaling
        UpperCAmelCase_            =  num_dynamic_real_features
        UpperCAmelCase_            =  num_static_real_features
        UpperCAmelCase_            =  num_static_categorical_features
        if cardinality and num_static_categorical_features > 0:
              if len(UpperCAmelCase__  ) != num_static_categorical_features:
                    raise ValueError(
                        '''The cardinality should be a list of the same length as `num_static_categorical_features`'''  )
              UpperCAmelCase_            =  cardinality
        else:
              UpperCAmelCase_            =  [0]
        if embedding_dimension and num_static_categorical_features > 0:
              if len(UpperCAmelCase__  ) != num_static_categorical_features:
                    raise ValueError(
                        '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''  )
              UpperCAmelCase_            =  embedding_dimension
        else:
              UpperCAmelCase_            =  [min(50  ,							(cat + 1) // 2  ) for cat in self.cardinality]
        UpperCAmelCase_            =  num_parallel_samples

        # Transformer architecture configuration
        UpperCAmelCase_            =  input_size * len(UpperCAmelCase__  ) + self._number_of_features
        UpperCAmelCase_            =  d_model
        UpperCAmelCase_            =  encoder_attention_heads
        UpperCAmelCase_            =  decoder_attention_heads
        UpperCAmelCase_            =  encoder_ffn_dim
        UpperCAmelCase_            =  decoder_ffn_dim
        UpperCAmelCase_            =  encoder_layers
        UpperCAmelCase_            =  decoder_layers

        UpperCAmelCase_            =  dropout
        UpperCAmelCase_            =  attention_dropout
        UpperCAmelCase_            =  activation_dropout
        UpperCAmelCase_            =  encoder_layerdrop
        UpperCAmelCase_            =  decoder_layerdrop

        UpperCAmelCase_            =  activation_function
        UpperCAmelCase_            =  init_std

        UpperCAmelCase_            =  use_cache

        super().__init__(is_encoder_decoder=UpperCAmelCase__  ,							**UpperCAmelCase__  )






  @property
  def  lowerCAmelCase__ (      self			:       List[str]  )				->int:
        return (
            sum(self.embedding_dimension  )
            + self.num_dynamic_real_features
            + self.num_time_features
            + self.num_static_real_features
            + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
        )





