

'''simple docstring'''


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

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



class        lowercase    (	a_			):


							def __init__(      self     ,      _snake_case     ,      _snake_case = None     ,      _snake_case = None     ,      _snake_case = None     ,      _snake_case = False     ,      _snake_case = False     ,      _snake_case = None     ,      **_snake_case     ,      )				->					List[Any]:
								super().__init__(
								    a_     ,      split=a_     ,      features=a_     ,      cache_dir=a_     ,      keep_in_memory=a_     ,      streaming=a_     ,      num_proc=a_     ,      **a_     ,      )
								UpperCAmelCase_		:   List[Any]													=       path_or_paths if isinstance(a_     ,      a_) else {self.split: path_or_paths}
								UpperCAmelCase_		:   Optional[Any]													=       Csv(
								    cache_dir=a_     ,      data_files=a_     ,      features=a_     ,      **a_     ,      )





							def     _snake_case				(      self)				->					str:
								# Build iterable dataset
								if self.streaming:
									UpperCAmelCase_		:   List[str]													=       self.builder.as_streaming_dataset(split=self.split)
								# Build regular (map-style) dataset
								else:
									UpperCAmelCase_		:   Any													=       None
									UpperCAmelCase_		:   Dict													=       None
									UpperCAmelCase_		:   List[str]													=       None
									UpperCAmelCase_		:   str													=       None

									self.builder.download_and_prepare(
									    download_config=a_     ,      download_mode=a_     ,      verification_mode=a_     ,      base_path=a_     ,      num_proc=self.num_proc     ,      )
									UpperCAmelCase_		:   Union[str, Any]													=       self.builder.as_dataset(
									    split=self.split     ,      verification_mode=a_     ,      in_memory=self.keep_in_memory)
								return dataset



class        lowercase    :


							def __init__(      self     ,      _snake_case     ,      _snake_case     ,      _snake_case = None     ,      _snake_case = None     ,      **_snake_case     ,      )				->					int:
								if num_proc is not None and num_proc <= 0:
									raise ValueError(F"""num_proc {num_proc} must be an integer > 0.""")

								UpperCAmelCase_		:   Any													=       dataset
								UpperCAmelCase_		:   List[str]													=       path_or_buf
								UpperCAmelCase_		:   Dict													=       batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
								UpperCAmelCase_		:   List[Any]													=       num_proc
								UpperCAmelCase_		:   int													=       'utf-8'
								UpperCAmelCase_		:   Union[str, Any]													=       to_csv_kwargs


							def     _snake_case				(      self)				->					Any:
								UpperCAmelCase_		:   Optional[Any]													=       self.to_csv_kwargs.pop('path_or_buf'     ,      a_)
								UpperCAmelCase_		:   Union[str, Any]													=       self.to_csv_kwargs.pop('header'     ,      a_)
								UpperCAmelCase_		:   List[Any]													=       self.to_csv_kwargs.pop('index'     ,      a_)

								if isinstance(self.path_or_buf     ,      (str, bytes, os.PathLike)):
									with open(self.path_or_buf     ,      'wb+') as buffer:
										UpperCAmelCase_		:   List[Any]													=       self._write(file_obj=a_     ,      header=a_     ,      index=a_     ,      **self.to_csv_kwargs)
								else:
									UpperCAmelCase_		:   Optional[int]													=       self._write(file_obj=self.path_or_buf     ,      header=a_     ,      index=a_     ,      **self.to_csv_kwargs)
								return written


							def     _snake_case				(      self     ,      _snake_case)				->					List[Any]:
								UpperCAmelCase_						,     UpperCAmelCase_						,     UpperCAmelCase_						,     UpperCAmelCase_		:   Optional[int]													=       args

								UpperCAmelCase_		:   Optional[Any]													=       query_table(
								    table=self.dataset.data     ,      key=slice(a_     ,      offset + self.batch_size)     ,      indices=self.dataset._indices     ,      )
								UpperCAmelCase_		:   List[str]													=       batch.to_pandas().to_csv(
								    path_or_buf=a_     ,      header=header if (offset == 0) else False     ,      index=a_     ,      **a_)
								return csv_str.encode(self.encoding)





							def     _snake_case				(      self     ,      _snake_case     ,      _snake_case     ,      _snake_case     ,      **_snake_case)				->					int:
								UpperCAmelCase_		:   Any													=       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 CSV from Arrow format'     ,      ):
										UpperCAmelCase_		:   Any													=       self._batch_csv((offset, header, index, to_csv_kwargs))
										written += file_obj.write(a_)

								else:
									UpperCAmelCase_						,     UpperCAmelCase_		:   List[Any]													=       len(self.dataset), self.batch_size
									with multiprocessing.Pool(self.num_proc) as pool:
										for csv_str in logging.tqdm(
										    pool.imap(
										        self._batch_csv     ,      [(offset, header, index, to_csv_kwargs) for offset in range(0     ,      a_     ,      a_)]     ,      )     ,      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 CSV from Arrow format'     ,      ):
											written += file_obj.write(a_)

								return written











UpperCAmelCase							=       (1, 153, 370, 371, 1_634, 24_678_051, 115_132_219_018_763_992_565_095_597_973_971_522_401)
UpperCAmelCase							=       (-153, -1, 0, 1.2, 200, "A", [], {}, None)

def       A_   (						__a  :					int		):

				"""simple docstring"""
				if not isinstance(__a			,		__a		) or n < 1:
								return False

				# Initialization of sum and number of digits.
				a__					   =		0
				a__					   =		0
				a__					   =		n
				# Calculation of digits of the number
				while temp > 0:
								number_of_digits += 1
								temp //= 10
				# Dividing number into separate digits and find Armstrong number
				a__					   =		n
				while temp > 0:
								a__					   =		temp % 10
								total += rem**number_of_digits
								temp //= 10
				return n == total

def       A_   (						__a  :					int		):

				"""simple docstring"""
				if not isinstance(__a			,		__a		) or n < 1:
								return False

				# Init a "histogram" of the digits
				a__					   =		[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
				a__					   =		0
				a__					   =		0
				a__					   =		n
				while temp > 0:
								a__   ,      a__					   =		divmod(__a			,		10		)
								digit_histogram[rem] += 1
								digit_total += 1

				for cnt, i in zip(__a			,		range(len(__a		)		)		):
								total += cnt * i**digit_total

				return n == total

def       A_   (						__a  :					int		):

				"""simple docstring"""
				if not isinstance(__a			,		__a		) or n < 1:
								return False
				a__					   =		len(str(__a		)		)  # the power that all digits will be raised to
				# check if sum of each digit multiplied expo times is equal to number
				return n == sum(int(__a		) ** expo for i in str(__a		)		)

def       A_   (						):

				"""simple docstring"""
				a__					   =		int(input("""Enter an integer to see if it is an Armstrong number: """		).strip()		)
				print(F'''{num} is {"" if armstrong_number(__a		) else "not "}an Armstrong number.'''		)
				print(F'''{num} is {"" if narcissistic_number(__a		) else "not "}an Armstrong number.'''		)
				print(F'''{num} is {"" if pluperfect_number(__a		) else "not "}an Armstrong number.'''		)


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	main()

