




"""simple docstring"""
import os
import tempfile
from pathlib import Path
from unittest import TestCase

import pyarrow as pa
import pytest

from datasets.arrow_dataset import Dataset
from datasets.arrow_reader import ArrowReader, BaseReader, FileInstructions, ReadInstruction, make_file_instructions
from datasets.info import DatasetInfo
from datasets.splits import NamedSplit, Split, SplitDict, SplitInfo

from .utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases







class  _SCREAMING_SNAKE_CASE       (     A__				):



 '''simple docstring'''





 def lowercase_      (self					,     lowerCAmelCase__					,     lowerCAmelCase__=False   ):

  '''simple docstring'''







  _UpperCamelCase      ,	_UpperCamelCase      ,	_UpperCamelCase      :	Optional[int]					      =  (
      filename_skip_take["filename"],
      filename_skip_take["skip"] if "skip" in filename_skip_take else None,
      filename_skip_take["take"] if "take" in filename_skip_take else None,
  )
  open(os.path.join(lowerCAmelCase__   )					,     "wb"   ).close()
  _UpperCamelCase      :	Optional[Any]					      =  pa.Table.from_pydict({"filename": [Path(lowerCAmelCase__   ).name] * 1_00}   )
  if take == -1:
   _UpperCamelCase      :	List[Any]					      =  len(lowerCAmelCase__   ) - skip
  if skip is not None and take is not None:
   _UpperCamelCase      :	List[str]					      =  pa_table.slice(lowerCAmelCase__					,     lowerCAmelCase__   )
  return pa_table







class  _SCREAMING_SNAKE_CASE       (     A__				):



 '''simple docstring'''





 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	List[str]					      =  "my_name"
  _UpperCamelCase      :	Tuple					      =  SplitInfo(name="train"					,     num_examples=1_00   )
  _UpperCamelCase      :	Union[str, Any]					      =  SplitInfo(name="test"					,     num_examples=1_00   )
  _UpperCamelCase      :	Union[str, Any]					      =  [train_info, test_info]
  _UpperCamelCase      :	List[str]					      =  SplitDict()
  split_dict.add(lowerCAmelCase__   )
  split_dict.add(lowerCAmelCase__   )
  _UpperCamelCase      :	Optional[int]					      =  DatasetInfo(splits=lowerCAmelCase__   )

  with tempfile.TemporaryDirectory() as tmp_dir:
   _UpperCamelCase      :	Optional[Any]					      =  ReaderTest(lowerCAmelCase__					,     lowerCAmelCase__   )

   _UpperCamelCase      :	Tuple					      =  "test[:33%]"
   _UpperCamelCase      :	str					      =  Dataset(**reader.read(lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__   )   )
   self.assertEqual(dset["filename"][0]					,     F"{name}-test"   )
   self.assertEqual(dset.num_rows					,     33   )
   self.assertEqual(dset.num_columns					,     1   )

   _UpperCamelCase      :	Any					      =  ["train", "test[:33%]"]
   _UpperCamelCase      :	str					      =  [Split.TRAIN, ReadInstruction.from_spec("test[:33%]"   )]
   for instructions in [instructionsa, instructionsa]:
    _UpperCamelCase      :	Optional[Any]					      =  [reader.read(lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__   ) for instr in instructions]
    _UpperCamelCase      ,	_UpperCamelCase      :	Union[str, Any]					      =  (Dataset(**lowerCAmelCase__   ) for dataset_kwargs in datasets_kwargs)
    self.assertEqual(train_dset["filename"][0]					,     F"{name}-train"   )
    self.assertEqual(train_dset.num_rows					,     1_00   )
    self.assertEqual(train_dset.num_columns					,     1   )
    self.assertIsInstance(train_dset.split					,     lowerCAmelCase__   )
    self.assertEqual(str(train_dset.split   )					,     "train"   )
    self.assertEqual(test_dset["filename"][0]					,     F"{name}-test"   )
    self.assertEqual(test_dset.num_rows					,     33   )
    self.assertEqual(test_dset.num_columns					,     1   )
    self.assertIsInstance(test_dset.split					,     lowerCAmelCase__   )
    self.assertEqual(str(test_dset.split   )					,     "test[:33%]"   )
    del train_dset, test_dset






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	List[str]					      =  "my_name"
  _UpperCamelCase      :	Dict					      =  SplitInfo(name="train"					,     num_examples=10_00					,     shard_lengths=[1_00] * 10   )
  _UpperCamelCase      :	List[str]					      =  [train_info]
  _UpperCamelCase      :	Optional[Any]					      =  SplitDict()
  split_dict.add(lowerCAmelCase__   )
  _UpperCamelCase      :	Optional[Any]					      =  DatasetInfo(splits=lowerCAmelCase__   )

  with tempfile.TemporaryDirectory() as tmp_dir:
   _UpperCamelCase      :	Tuple					      =  ReaderTest(lowerCAmelCase__					,     lowerCAmelCase__   )

   _UpperCamelCase      :	Any					      =  "train[:33%]"
   _UpperCamelCase      :	int					      =  Dataset(**reader.read(lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__   )   )
   self.assertEqual(dset["filename"][0]					,     F"{name}-train-00000-of-00010"   )
   self.assertEqual(dset["filename"][-1]					,     F"{name}-train-00003-of-00010"   )
   self.assertEqual(dset.num_rows					,     3_30   )
   self.assertEqual(dset.num_columns					,     1   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Union[str, Any]					      =  SplitInfo(name="train"					,     num_examples=1_00   )
  _UpperCamelCase      :	Any					      =  SplitInfo(name="test"					,     num_examples=1_00   )
  _UpperCamelCase      :	int					      =  SplitDict()
  split_dict.add(lowerCAmelCase__   )
  split_dict.add(lowerCAmelCase__   )
  _UpperCamelCase      :	List[str]					      =  DatasetInfo(splits=lowerCAmelCase__   )

  with tempfile.TemporaryDirectory() as tmp_dir:
   _UpperCamelCase      :	Union[str, Any]					      =  ReaderTest(lowerCAmelCase__					,     lowerCAmelCase__   )

   _UpperCamelCase      :	Tuple					      =  [
       {"filename": os.path.join(lowerCAmelCase__					,     "train"   )},
       {"filename": os.path.join(lowerCAmelCase__					,     "test"   ), "skip": 10, "take": 10},
   ]
   _UpperCamelCase      :	str					      =  Dataset(**reader.read_files(lowerCAmelCase__					,     original_instructions="train+test[10:20]"   )   )
   self.assertEqual(dset.num_rows					,     1_10   )
   self.assertEqual(dset.num_columns					,     1   )
   del dset






@pytest.mark.parametrize("in_memory"  ,	[False, True]						)
def 				__lowerCAmelCase					(					__lowerCAmelCase			:		Any  ,	__lowerCAmelCase			:		List[str]  ,	__lowerCAmelCase			:		List[Any]						)    ->       List[Any]:
 _UpperCamelCase      :	Optional[Any]					      =  arrow_file
 with assert_arrow_memory_increases() if in_memory else assert_arrow_memory_doesnt_increase():
  _UpperCamelCase      :	int					      =  ArrowReader.read_table(a__  ,	in_memory=a__						)
 assert table.shape == dataset.data.shape
 assert set(table.column_names						) == set(dataset.data.column_names						)
 assert dict(table.to_pydict()						) == dict(dataset.data.to_pydict()						)  # to_pydict returns OrderedDict






@pytest.mark.parametrize("in_memory"  ,	[False, True]						)
def 				__lowerCAmelCase					(					__lowerCAmelCase			:		List[str]  ,	__lowerCAmelCase			:		Optional[Any]  ,	__lowerCAmelCase			:		Optional[Any]						)    ->       Tuple:
 _UpperCamelCase      :	int					      =  arrow_file
 _UpperCamelCase      :	List[str]					      =  ArrowReader(""  ,	a__						)
 with assert_arrow_memory_increases() if in_memory else assert_arrow_memory_doesnt_increase():
  _UpperCamelCase      :	int					      =  reader.read_files([{"filename": filename}]  ,	in_memory=a__						)
 assert dataset_kwargs.keys() == {"arrow_table", "info", "split"}
 _UpperCamelCase      :	Any					      =  dataset_kwargs["arrow_table"]
 assert table.shape == dataset.data.shape
 assert set(table.column_names						) == set(dataset.data.column_names						)
 assert dict(table.to_pydict()						) == dict(dataset.data.to_pydict()						)  # to_pydict returns OrderedDict






def 				__lowerCAmelCase					(					)    ->       Optional[int]:
 assert ReadInstruction("train"  ,	to=10  ,	unit="abs"						).to_spec() == "train[:10]"
 assert ReadInstruction("train"  ,	from_=-80  ,	to=10  ,	unit="%"						).to_spec() == "train[-80%:10%]"

 _UpperCamelCase      :	Optional[Any]					      =  "train+test"
 assert ReadInstruction.from_spec(a__						).to_spec() == spec_train_test

 _UpperCamelCase      :	List[str]					      =  "train[2:10]"
 assert ReadInstruction.from_spec(a__						).to_spec() == spec_train_abs

 _UpperCamelCase      :	Any					      =  "train[15%:-20%]"
 assert ReadInstruction.from_spec(a__						).to_spec() == spec_train_pct

 _UpperCamelCase      :	Optional[int]					      =  "train[:10%](closest)"
 assert ReadInstruction.from_spec(a__						).to_spec() == "train[:10%]"

 _UpperCamelCase      :	int					      =  "train[:10%](pct1_dropremainder)"
 assert ReadInstruction.from_spec(a__						).to_spec() == spec_train_pct_rounding

 _UpperCamelCase      :	Dict					      =  "train[:10%](pct1_dropremainder)+test[-10%:](pct1_dropremainder)"
 assert ReadInstruction.from_spec(a__						).to_spec() == spec_train_test_pct_rounding






def 				__lowerCAmelCase					(					)    ->       Optional[Any]:
 _UpperCamelCase      :	List[Any]					      =  "dummy"
 _UpperCamelCase      :	str					      =  [SplitInfo(name="train"  ,	num_examples=100						)]
 _UpperCamelCase      :	int					      =  "train[:33%]"
 _UpperCamelCase      :	int					      =  "arrow"
 _UpperCamelCase      :	str					      =  "prefix"

 _UpperCamelCase      :	Optional[Any]					      =  make_file_instructions(a__  ,	a__  ,	a__  ,	a__  ,	a__						)
 assert isinstance(a__  ,	a__						)
 assert file_instructions.num_examples == 33
 assert file_instructions.file_instructions == [
     {"filename": os.path.join(a__  ,	f"{name}-train.arrow"						), "skip": 0, "take": 33}
 ]

 _UpperCamelCase      :	List[Any]					      =  [SplitInfo(name="train"  ,	num_examples=100  ,	shard_lengths=[10] * 10						)]
 _UpperCamelCase      :	Optional[int]					      =  make_file_instructions(a__  ,	a__  ,	a__  ,	a__  ,	a__						)
 assert isinstance(a__  ,	a__						)
 assert file_instructions.num_examples == 33
 assert file_instructions.file_instructions == [
     {"filename": os.path.join(a__  ,	f"{name}-train-00000-of-00010.arrow"						), "skip": 0, "take": -1},
     {"filename": os.path.join(a__  ,	f"{name}-train-00001-of-00010.arrow"						), "skip": 0, "take": -1},
     {"filename": os.path.join(a__  ,	f"{name}-train-00002-of-00010.arrow"						), "skip": 0, "take": -1},
     {"filename": os.path.join(a__  ,	f"{name}-train-00003-of-00010.arrow"						), "skip": 0, "take": 3},
 ]






@pytest.mark.parametrize("name, expected_exception"  ,	[(None, TypeError), ("", ValueError)]						)
def 				__lowerCAmelCase					(					__lowerCAmelCase			:		List[str]  ,	__lowerCAmelCase			:		Tuple						)    ->       List[Any]:
 _UpperCamelCase      :	Optional[Any]					      =  [SplitInfo(name="train"  ,	num_examples=100						)]
 _UpperCamelCase      :	Dict					      =  "train"
 _UpperCamelCase      :	str					      =  "arrow"
 _UpperCamelCase      :	Optional[int]					      =  "prefix_path"
 with pytest.raises(a__						):
  _UpperCamelCase      :	List[str]					      =  make_file_instructions(a__  ,	a__  ,	a__  ,	a__  ,	a__						)





'''simple docstring'''







from collections import defaultdict







def   lowerCAmelCase(  a__    :  int = 5      ):







       '''simple docstring'''






       lowerCamelCase__				   =      defaultdict(a__      )
       lowerCamelCase__				   =      0

       while True:
              lowerCamelCase__				   =      get_digits(a__      )
              freqs[digits].append(a__      )

              if len(freqs[digits]      ) == max_base:
                     lowerCamelCase__				   =      freqs[digits][0] ** 3
                     return base

              num += 1







def   lowerCAmelCase(  a__    :  int      ):







       '''simple docstring'''






       return "".join(sorted(str(num**3      )      )      )


if __name__ == "__main__":
    print(f'{solution() = }')

