code: 
  
  
  '''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      UpperCAmelCase_						(UpperCamelCase__						):
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
      def    lowercase_       (							self    ,  SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_=False			)       ->  List[Any]:
           __lowerCamelCase     :			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()
           __lowerCamelCase     :			Optional[int]              =	pa.Table.from_pydict({'filename': [Path(lowerCAmelCase__			).name] * 1_00}			)
           if take == -1:
                __lowerCamelCase     :			int              =	len(lowerCAmelCase__			) - skip
           if skip is not None and take is not None:
                __lowerCamelCase     :			Optional[Any]              =	pa_table.slice(lowerCAmelCase__    ,  lowerCAmelCase__			)
           return pa_table
  
  
  
  
  
  
  
  class      UpperCAmelCase_						(UpperCamelCase__						):
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
      def    lowercase_       (							self			)       ->  str:
           __lowerCamelCase     :			List[str]              =	"my_name"
           __lowerCamelCase     :			List[Any]              =	SplitInfo(name='train'    ,  num_examples=1_00			)
           __lowerCamelCase     :			List[str]              =	SplitInfo(name='test'    ,  num_examples=1_00			)
           __lowerCamelCase     :			List[Any]              =	[train_info, test_info]
           __lowerCamelCase     :			Union[str, Any]              =	SplitDict()
           split_dict.add(lowerCAmelCase__			)
           split_dict.add(lowerCAmelCase__			)
           __lowerCamelCase     :			Dict              =	DatasetInfo(splits=lowerCAmelCase__			)
  
           with tempfile.TemporaryDirectory() as tmp_dir:
                __lowerCamelCase     :			Optional[Any]              =	ReaderTest(lowerCAmelCase__    ,  lowerCAmelCase__			)
  
                __lowerCamelCase     :			Any              =	"test[:33%]"
                __lowerCamelCase     :			int              =	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			)
  
                __lowerCamelCase     :			Tuple              =	["train", "test[:33%]"]
                __lowerCamelCase     :			str              =	[Split.TRAIN, ReadInstruction.from_spec('test[:33%]'			)]
                for instructions in [instructionsa, instructionsa]:
                     __lowerCamelCase     :			Optional[int]              =	[reader.read(lowerCAmelCase__    ,  lowerCAmelCase__    ,  lowerCAmelCase__			) for instr in instructions]
                     __lowerCamelCase     :			Optional[int]              =	(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			)       ->  Optional[Any]:
           __lowerCamelCase     :			Any              =	"my_name"
           __lowerCamelCase     :			List[Any]              =	SplitInfo(name='train'    ,  num_examples=10_00    ,  shard_lengths=[1_00] * 10			)
           __lowerCamelCase     :			Optional[Any]              =	[train_info]
           __lowerCamelCase     :			Any              =	SplitDict()
           split_dict.add(lowerCAmelCase__			)
           __lowerCamelCase     :			Any              =	DatasetInfo(splits=lowerCAmelCase__			)
  
           with tempfile.TemporaryDirectory() as tmp_dir:
                __lowerCamelCase     :			Optional[int]              =	ReaderTest(lowerCAmelCase__    ,  lowerCAmelCase__			)
  
                __lowerCamelCase     :			Union[str, Any]              =	"train[:33%]"
                __lowerCamelCase     :			Union[str, Any]              =	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			)       ->  List[str]:
           __lowerCamelCase     :			Dict              =	SplitInfo(name='train'    ,  num_examples=1_00			)
           __lowerCamelCase     :			str              =	SplitInfo(name='test'    ,  num_examples=1_00			)
           __lowerCamelCase     :			int              =	SplitDict()
           split_dict.add(lowerCAmelCase__			)
           split_dict.add(lowerCAmelCase__			)
           __lowerCamelCase     :			int              =	DatasetInfo(splits=lowerCAmelCase__			)
  
           with tempfile.TemporaryDirectory() as tmp_dir:
                __lowerCamelCase     :			Tuple              =	ReaderTest(lowerCAmelCase__    ,  lowerCAmelCase__			)
  
                __lowerCamelCase     :			Tuple              =	[
                    {"filename": os.path.join(lowerCAmelCase__    ,  'train'			)},
                    {"filename": os.path.join(lowerCAmelCase__    ,  'test'			), "skip": 10, "take": 10},
                ]
                __lowerCamelCase     :			Optional[Any]              =	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     UpperCAmelCase__      (			UpperCAmelCase_					:       Optional[Any]   ,					UpperCAmelCase_					:       Optional[Any]   ,					UpperCAmelCase_					:       Optional[Any]							)  ->	List[str]:
       __lowerCamelCase     :			int              =	arrow_file
       with assert_arrow_memory_increases() if in_memory else assert_arrow_memory_doesnt_increase():
            __lowerCamelCase     :			str              =	ArrowReader.read_table(UpperCAmelCase_   ,					in_memory=UpperCAmelCase_							)
       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     UpperCAmelCase__      (			UpperCAmelCase_					:       Tuple   ,					UpperCAmelCase_					:       List[Any]   ,					UpperCAmelCase_					:       str							)  ->	Optional[int]:
       __lowerCamelCase     :			Optional[int]              =	arrow_file
       __lowerCamelCase     :			Tuple              =	ArrowReader(''   ,					UpperCAmelCase_							)
       with assert_arrow_memory_increases() if in_memory else assert_arrow_memory_doesnt_increase():
            __lowerCamelCase     :			Union[str, Any]              =	reader.read_files([{'filename': filename}]   ,					in_memory=UpperCAmelCase_							)
       assert dataset_kwargs.keys() == {"arrow_table", "info", "split"}
       __lowerCamelCase     :			Dict              =	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     UpperCAmelCase__      (			)  ->	Tuple:
       assert ReadInstruction('train'   ,					to=10   ,					unit='abs'							).to_spec() == "train[:10]"
       assert ReadInstruction('train'   ,					from_=-80   ,					to=10   ,					unit='%'							).to_spec() == "train[-80%:10%]"
  
       __lowerCamelCase     :			List[Any]              =	"train+test"
       assert ReadInstruction.from_spec(UpperCAmelCase_							).to_spec() == spec_train_test
  
       __lowerCamelCase     :			Union[str, Any]              =	"train[2:10]"
       assert ReadInstruction.from_spec(UpperCAmelCase_							).to_spec() == spec_train_abs
  
       __lowerCamelCase     :			List[Any]              =	"train[15%:-20%]"
       assert ReadInstruction.from_spec(UpperCAmelCase_							).to_spec() == spec_train_pct
  
       __lowerCamelCase     :			Dict              =	"train[:10%](closest)"
       assert ReadInstruction.from_spec(UpperCAmelCase_							).to_spec() == "train[:10%]"
  
       __lowerCamelCase     :			Tuple              =	"train[:10%](pct1_dropremainder)"
       assert ReadInstruction.from_spec(UpperCAmelCase_							).to_spec() == spec_train_pct_rounding
  
       __lowerCamelCase     :			List[Any]              =	"train[:10%](pct1_dropremainder)+test[-10%:](pct1_dropremainder)"
       assert ReadInstruction.from_spec(UpperCAmelCase_							).to_spec() == spec_train_test_pct_rounding
  
  
  
  def     UpperCAmelCase__      (			)  ->	Optional[Any]:
       __lowerCamelCase     :			Optional[Any]              =	"dummy"
       __lowerCamelCase     :			Dict              =	[SplitInfo(name='train'   ,					num_examples=1_00							)]
       __lowerCamelCase     :			Optional[Any]              =	"train[:33%]"
       __lowerCamelCase     :			int              =	"arrow"
       __lowerCamelCase     :			Any              =	"prefix"
  
       __lowerCamelCase     :			Tuple              =	make_file_instructions(UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_							)
       assert isinstance(UpperCAmelCase_   ,					UpperCAmelCase_							)
       assert file_instructions.num_examples == 33
       assert file_instructions.file_instructions == [
           {"filename": os.path.join(UpperCAmelCase_   ,					F'{name}-train.arrow'							), "skip": 0, "take": 33}
       ]
  
       __lowerCamelCase     :			List[str]              =	[SplitInfo(name='train'   ,					num_examples=1_00   ,					shard_lengths=[10] * 10							)]
       __lowerCamelCase     :			Union[str, Any]              =	make_file_instructions(UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_							)
       assert isinstance(UpperCAmelCase_   ,					UpperCAmelCase_							)
       assert file_instructions.num_examples == 33
       assert file_instructions.file_instructions == [
           {"filename": os.path.join(UpperCAmelCase_   ,					F'{name}-train-00000-of-00010.arrow'							), "skip": 0, "take": -1},
           {"filename": os.path.join(UpperCAmelCase_   ,					F'{name}-train-00001-of-00010.arrow'							), "skip": 0, "take": -1},
           {"filename": os.path.join(UpperCAmelCase_   ,					F'{name}-train-00002-of-00010.arrow'							), "skip": 0, "take": -1},
           {"filename": os.path.join(UpperCAmelCase_   ,					F'{name}-train-00003-of-00010.arrow'							), "skip": 0, "take": 3},
       ]
  
  
  
  @pytest.mark.parametrize('name, expected_exception'   ,					[(None, TypeError), ('', ValueError)]							)
  def     UpperCAmelCase__      (			UpperCAmelCase_					:       Tuple   ,					UpperCAmelCase_					:       Tuple							)  ->	Optional[Any]:
       __lowerCamelCase     :			Dict              =	[SplitInfo(name='train'   ,					num_examples=1_00							)]
       __lowerCamelCase     :			Any              =	"train"
       __lowerCamelCase     :			Optional[Any]              =	"arrow"
       __lowerCamelCase     :			List[Any]              =	"prefix_path"
       with pytest.raises(UpperCAmelCase_							):
            __lowerCamelCase     :			Optional[Any]              =	make_file_instructions(UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_   ,					UpperCAmelCase_							)
  
  
  
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  
  
  def     UpperCAmelCase__      (			UpperCAmelCase_					:       str							)  ->	int:
       __lowerCamelCase     :			Tuple              =	str(UpperCAmelCase_							).strip()
       if not bin_string:
            raise ValueError('Empty string was passed to the function'							)
       __lowerCamelCase     :			Optional[int]              =	bin_string[0] == '-'
       if is_negative:
            __lowerCamelCase     :			List[Any]              =	bin_string[1:]
       if not all(char in '01' for char in bin_string							):
            raise ValueError('Non-binary value was passed to the function'							)
       __lowerCamelCase     :			Optional[int]              =	0
       for char in bin_string:
            __lowerCamelCase     :			str              =	2 * decimal_number + int(UpperCAmelCase_							)
       return -decimal_number if is_negative else decimal_number
  
  
  if __name__ == "__main__":
        from doctest import testmod
  
        testmod()
  
  
  
  
  
  
  