






import multiprocessing
import os
from typing import BinaryIO, Optional, Union

import fsspec

from .. import Dataset, Features, NamedSplit, config
from ..formatting import query_table
from ..packaged_modules.json.json import Json
from ..utils import logging
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader





class       __a  (   A__	):







 def __init__(		self :       Optional[Any]							,       SCREAMING_SNAKE_CASE :       NestedDataStructureLike[PathLike]							,       SCREAMING_SNAKE_CASE :       Optional[NamedSplit] = None							,       SCREAMING_SNAKE_CASE :       Optional[Features] = None							,       SCREAMING_SNAKE_CASE :       str = None							,       SCREAMING_SNAKE_CASE :       bool = False							,       SCREAMING_SNAKE_CASE :       bool = False							,       SCREAMING_SNAKE_CASE :       Optional[str] = None							,       SCREAMING_SNAKE_CASE :       Optional[int] = None							,       **SCREAMING_SNAKE_CASE :       Any							,       ):


      '''simple docstring'''






      super().__init__(
          SCREAMING_SNAKE_CASE							,       split=SCREAMING_SNAKE_CASE							,       features=SCREAMING_SNAKE_CASE							,       cache_dir=SCREAMING_SNAKE_CASE							,       keep_in_memory=SCREAMING_SNAKE_CASE							,       streaming=SCREAMING_SNAKE_CASE							,       num_proc=SCREAMING_SNAKE_CASE							,       **SCREAMING_SNAKE_CASE							,       )
      UpperCamelCase__      :       Any	    =  field
      UpperCamelCase__      :       Any	    =  path_or_paths if isinstance(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						) else {self.split: path_or_paths}
      UpperCamelCase__      :       List[str]	    =  Json(
          cache_dir=SCREAMING_SNAKE_CASE							,       data_files=SCREAMING_SNAKE_CASE							,       features=SCREAMING_SNAKE_CASE							,       field=SCREAMING_SNAKE_CASE							,       **SCREAMING_SNAKE_CASE							,       )







 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      if self.streaming:
           UpperCamelCase__      :       Union[str, Any]	    =  self.builder.as_streaming_dataset(split=self.split						)
      # Build regular (map-style) dataset
      else:
           UpperCamelCase__      :       Optional[Any]	    =  None
           UpperCamelCase__      :       Union[str, Any]	    =  None
           UpperCamelCase__      :       Optional[Any]	    =  None
           UpperCamelCase__      :       Union[str, Any]	    =  None

           self.builder.download_and_prepare(
               download_config=SCREAMING_SNAKE_CASE							,       download_mode=SCREAMING_SNAKE_CASE							,       verification_mode=SCREAMING_SNAKE_CASE							,       base_path=SCREAMING_SNAKE_CASE							,       num_proc=self.num_proc							,       )
           UpperCamelCase__      :       str	    =  self.builder.as_dataset(
               split=self.split							,       verification_mode=SCREAMING_SNAKE_CASE							,       in_memory=self.keep_in_memory						)
      return dataset







class       __a  :







 def __init__(		self :       List[str]							,       SCREAMING_SNAKE_CASE :       Dataset							,       SCREAMING_SNAKE_CASE :       Union[PathLike, BinaryIO]							,       SCREAMING_SNAKE_CASE :       Optional[int] = None							,       SCREAMING_SNAKE_CASE :       Optional[int] = None							,       **SCREAMING_SNAKE_CASE :       Optional[int]							,       ):


      '''simple docstring'''






      if num_proc is not None and num_proc <= 0:
           raise ValueError(F'num_proc {num_proc} must be an integer > 0.'						)

      UpperCamelCase__      :       str	    =  dataset
      UpperCamelCase__      :       Dict	    =  path_or_buf
      UpperCamelCase__      :       List[str]	    =  batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
      UpperCamelCase__      :       Optional[Any]	    =  num_proc
      UpperCamelCase__      :       Tuple	    =  "utf-8"
      UpperCamelCase__      :       Dict	    =  to_json_kwargs







 def  __lowercase (		self :       str						):


      '''simple docstring'''






      UpperCamelCase__      :       List[Any]	    =  self.to_json_kwargs.pop("path_or_buf"							,       SCREAMING_SNAKE_CASE						)
      UpperCamelCase__      :       Dict	    =  self.to_json_kwargs.pop("orient"							,       "records"						)
      UpperCamelCase__      :       Any	    =  self.to_json_kwargs.pop("lines"							,       True if orient == "records" else False						)
      UpperCamelCase__      :       Optional[int]	    =  self.to_json_kwargs.pop("index"							,       False if orient in ["split", "table"] else True						)
      UpperCamelCase__      :       Any	    =  self.to_json_kwargs.pop("compression"							,       SCREAMING_SNAKE_CASE						)

      if compression not in [None, "infer", "gzip", "bz2", "xz"]:
           raise NotImplementedError(F'`datasets` currently does not support {compression} compression'						)

      if isinstance(self.path_or_buf							,       (str, bytes, os.PathLike)						):
           with fsspec.open(self.path_or_buf							,       "wb"							,       compression=SCREAMING_SNAKE_CASE						) as buffer:
                UpperCamelCase__      :       str	    =  self._write(file_obj=SCREAMING_SNAKE_CASE							,       orient=SCREAMING_SNAKE_CASE							,       lines=SCREAMING_SNAKE_CASE							,       index=SCREAMING_SNAKE_CASE							,       **self.to_json_kwargs						)
      else:
           if compression:
                raise NotImplementedError(
                    F'The compression parameter is not supported when writing to a buffer, but compression={compression}'
                    " was passed. Please provide a local path instead."						)
           UpperCamelCase__      :       Tuple	    =  self._write(
               file_obj=self.path_or_buf							,       orient=SCREAMING_SNAKE_CASE							,       lines=SCREAMING_SNAKE_CASE							,       index=SCREAMING_SNAKE_CASE							,       **self.to_json_kwargs						)
      return written







 def  __lowercase (		self :       List[str]							,       SCREAMING_SNAKE_CASE :       str						):


      '''simple docstring'''






      UpperCamelCase__    ,					UpperCamelCase__    ,					UpperCamelCase__    ,					UpperCamelCase__    ,					UpperCamelCase__      :       int	    =  args

      UpperCamelCase__      :       List[Any]	    =  query_table(
          table=self.dataset.data							,       key=slice(SCREAMING_SNAKE_CASE							,       offset + self.batch_size						)							,       indices=self.dataset._indices							,       )
      UpperCamelCase__      :       Dict	    =  batch.to_pandas().to_json(
          path_or_buf=SCREAMING_SNAKE_CASE							,       orient=SCREAMING_SNAKE_CASE							,       lines=SCREAMING_SNAKE_CASE							,       index=SCREAMING_SNAKE_CASE							,       **SCREAMING_SNAKE_CASE						)
      if not json_str.endswith("\n"						):
           json_str += "\n"
      return json_str.encode(self.encoding						)







 def  __lowercase (		self :       Tuple							,       SCREAMING_SNAKE_CASE :       BinaryIO							,       SCREAMING_SNAKE_CASE :       Dict							,       SCREAMING_SNAKE_CASE :       List[Any]							,       SCREAMING_SNAKE_CASE :       Tuple							,       **SCREAMING_SNAKE_CASE :       Optional[int]							,       ):


      '''simple docstring'''






      UpperCamelCase__      :       List[str]	    =  0

      if self.num_proc is None or self.num_proc == 1:
           for offset in logging.tqdm(
               range(0							,       len(self.dataset						)							,       self.batch_size						)							,       unit="ba"							,       disable=not logging.is_progress_bar_enabled()							,       desc="Creating json from Arrow format"							,       ):
                UpperCamelCase__      :       Any	    =  self._batch_json((offset, orient, lines, index, to_json_kwargs)						)
                written += file_obj.write(SCREAMING_SNAKE_CASE						)
      else:
           UpperCamelCase__    ,					UpperCamelCase__      :       Optional[int]	    =  len(self.dataset						), self.batch_size
           with multiprocessing.Pool(self.num_proc						) as pool:
                for json_str in logging.tqdm(
                    pool.imap(
                        self._batch_json							,       [(offset, orient, lines, index, to_json_kwargs) for offset in range(0							,       SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						)]							,       )							,       total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size							,       unit="ba"							,       disable=not logging.is_progress_bar_enabled()							,       desc="Creating json from Arrow format"							,       ):
                     written += file_obj.write(SCREAMING_SNAKE_CASE						)

      return written







from __future__ import annotations







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase ,   __lowerCAmelCase      )			->     list[int]:
     UpperCamelCase__      :       Optional[Any]	    =  0
     UpperCamelCase__      :       Any	    =  len(__lowerCAmelCase      ) - 1

     while i < j:
          if nums[i] + nums[j] == target:
               return [i, j]
          elif nums[i] + nums[j] < target:
               UpperCamelCase__      :       Optional[int]	    =  i + 1
          else:
               UpperCamelCase__      :       Dict	    =  j - 1

     return []


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 print(F"""{two_pointer([2, 7, 11, 15], 9) = }""")