






'''simple docstring'''

import os
from typing import BinaryIO, Optional, Union

import numpy as np
import pyarrow.parquet as pq

from .. import Audio, Dataset, Features, Image, NamedSplit, Value, config
from ..features.features import FeatureType, _visit
from ..formatting import query_table
from ..packaged_modules import _PACKAGED_DATASETS_MODULES
from ..packaged_modules.parquet.parquet import Parquet
from ..utils import logging
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader



def 							snake_case					(     a_							: Features	)       ->				Optional[int]:





      """simple docstring"""

      UpperCamelCase_				:   str					    =							np.inf

      def set_batch_size(a_							: FeatureType	) -> None:
            nonlocal batch_size
            if isinstance(a_    ,   a_	):
                  UpperCamelCase_				:   Union[str, Any]					    =							min(a_    ,   config.PARQUET_ROW_GROUP_SIZE_FOR_IMAGE_DATASETS	)
            elif isinstance(a_    ,   a_	):
                  UpperCamelCase_				:   List[Any]					    =							min(a_    ,   config.PARQUET_ROW_GROUP_SIZE_FOR_AUDIO_DATASETS	)
            elif isinstance(a_    ,   a_	) and feature.dtype == "binary":
                  UpperCamelCase_				:   List[Any]					    =							min(a_    ,   config.PARQUET_ROW_GROUP_SIZE_FOR_BINARY_DATASETS	)

      _visit(a_    ,   a_	)

      return None if batch_size is np.inf else batch_size




class     A    (      SCREAMING_SNAKE_CASE__						):






 """simple docstring"""





 def __init__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase = None			,     __lowerCAmelCase = None			,     __lowerCAmelCase = None			,     __lowerCAmelCase = False			,     __lowerCAmelCase = False			,     __lowerCAmelCase = None			,     **__lowerCAmelCase			,     ):
       super().__init__(
           __lowerCAmelCase			,     split=__lowerCAmelCase			,     features=__lowerCAmelCase			,     cache_dir=__lowerCAmelCase			,     keep_in_memory=__lowerCAmelCase			,     streaming=__lowerCAmelCase			,     num_proc=__lowerCAmelCase			,     **__lowerCAmelCase			,     )
       UpperCamelCase_				:   Tuple					    =							path_or_paths if isinstance(__lowerCAmelCase			,     __lowerCAmelCase ) else {self.split: path_or_paths}
       UpperCamelCase_				:   int					    =							_PACKAGED_DATASETS_MODULES["""parquet"""][1]
       UpperCamelCase_				:   Optional[Any]					    =							Parquet(
           cache_dir=__lowerCAmelCase			,     data_files=__lowerCAmelCase			,     features=__lowerCAmelCase			,     hash=__lowerCAmelCase			,     **__lowerCAmelCase			,     )





 def   _UpperCAmelCase       (							self ):
       # Build iterable dataset
       if self.streaming:
             UpperCamelCase_				:   Tuple					    =							self.builder.as_streaming_dataset(split=self.split )
       # Build regular (map-style) dataset
       else:
             UpperCamelCase_				:   Dict					    =							None
             UpperCamelCase_				:   int					    =							None
             UpperCamelCase_				:   str					    =							None
             UpperCamelCase_				:   int					    =							None

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






class     A    :






 """simple docstring"""





 def __init__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase			,     __lowerCAmelCase = None			,     **__lowerCAmelCase			,     ):
       UpperCamelCase_				:   Tuple					    =							dataset
       UpperCamelCase_				:   List[Any]					    =							path_or_buf
       UpperCamelCase_				:   Union[str, Any]					    =							batch_size or get_writer_batch_size(dataset.features )
       UpperCamelCase_				:   Dict					    =							parquet_writer_kwargs
 def   _UpperCAmelCase       (							self ):
       UpperCamelCase_				:   Dict					    =							self.batch_size if self.batch_size else config.DEFAULT_MAX_BATCH_SIZE

       if isinstance(self.path_or_buf			,     (str, bytes, os.PathLike) ):
             with open(self.path_or_buf			,     """wb+""" ) as buffer:
                   UpperCamelCase_				:   int					    =							self._write(file_obj=__lowerCAmelCase			,     batch_size=__lowerCAmelCase			,     **self.parquet_writer_kwargs )
       else:
             UpperCamelCase_				:   int					    =							self._write(file_obj=self.path_or_buf			,     batch_size=__lowerCAmelCase			,     **self.parquet_writer_kwargs )
       return written





 def   _UpperCAmelCase       (							self			,     __lowerCAmelCase			,     __lowerCAmelCase			,     **__lowerCAmelCase ):
       UpperCamelCase_				:   Dict					    =							0
       UpperCamelCase_				:   Any					    =							parquet_writer_kwargs.pop("""path_or_buf"""			,     __lowerCAmelCase )
       UpperCamelCase_				:   str					    =							self.dataset.features.arrow_schema

       UpperCamelCase_				:   Tuple					    =							pq.ParquetWriter(__lowerCAmelCase			,     schema=__lowerCAmelCase			,     **__lowerCAmelCase )

       for offset in logging.tqdm(
           range(0			,     len(self.dataset )			,     __lowerCAmelCase )			,     unit="""ba"""			,     disable=not logging.is_progress_bar_enabled()			,     desc="""Creating parquet from Arrow format"""			,     ):
             UpperCamelCase_				:   Union[str, Any]					    =							query_table(
                 table=self.dataset._data			,     key=slice(__lowerCAmelCase			,     offset + batch_size )			,     indices=self.dataset._indices if self.dataset._indices is not None else None			,     )
             writer.write_table(__lowerCAmelCase )
             written += batch.nbytes
       writer.close()
       return written














'''simple docstring'''

from __future__ import annotations

import os
from typing import Any

import requests

UpperCamelCase							="https://api.github.com"

# https://docs.github.com/en/free-pro-team@latest/rest/reference/users#get-the-authenticated-user
UpperCamelCase							=BASE_URL + "/user"

# https://github.com/settings/tokens
UpperCamelCase							=os.environ.get("USER_TOKEN", "")



def 							snake_case					(     a_							: str	)       ->				dict[Any, Any]:





      """simple docstring"""

      UpperCamelCase_				:   Tuple					    =							{
          """Authorization""": f"token {auth_token}",
          """Accept""": """application/vnd.github.v3+json""",
      }
      return requests.get(a_    ,   headers=a_	).json()


if __name__ == "__main__":  # pragma: no cover
      if USER_TOKEN:
            for key, value in fetch_github_info(USER_TOKEN).items():
                  print(f"{key}: {value}")
      else:
            raise ValueError("'USER_TOKEN' field cannot be empty.")






