


"""simple docstring"""







import copy
import os
import tempfile
from unittest import TestCase
from unittest.mock import patch

import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq
import pytest

from datasets.arrow_writer import ArrowWriter, OptimizedTypedSequence, ParquetWriter, TypedSequence
from datasets.features import ArrayaD, ClassLabel, Features, Image, Value
from datasets.features.features import ArrayaDExtensionType, cast_to_python_objects
from datasets.keyhash import DuplicatedKeysError, InvalidKeyError

from .utils import require_pil


class 				SCREAMING_SNAKE_CASE__    (		lowercase    ):
       """simple docstring"""


       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Union[str, Any]								=							pa.array(TypedSequence([1, 2, 3]						)						)
         self.assertEqual(arr.type		,					pa.intaa()						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         with self.assertRaises(snake_case__						):
           lowerCAmelCase					:					str								=							pa.array(TypedSequence([1, 2, 3]						)		,					type=pa.intaa()						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         with self.assertRaises(snake_case__						):
           lowerCAmelCase					:					List[str]								=							pa.array(TypedSequence([1, 2, 3]		,					try_type=Value("bool"						)		,					type=Value("int64"						)						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Union[str, Any]								=							pa.array(TypedSequence([1, 2, 3]		,					type=Value("int32"						)						)						)
         self.assertEqual(arr.type		,					pa.intaa()						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         with self.assertRaises((TypeError, pa.lib.ArrowInvalid)						):
           lowerCAmelCase					:					Optional[Any]								=							pa.array(TypedSequence(["foo", "bar"]		,					type=Value("int64"						)						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					List[str]								=							pa.array(TypedSequence([1, 2, 3]		,					try_type=Value("int32"						)						)						)
         self.assertEqual(arr.type		,					pa.intaa()						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Union[str, Any]								=							pa.array(TypedSequence(["foo", "bar"]		,					try_type=Value("int64"						)						)						)
         self.assertEqual(arr.type		,					pa.string()						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					str								=							pa.array(TypedSequence([[[1, 2, 3]]]		,					type=ArrayaD((1, 3)		,					"int64"						)						)						)
         self.assertEqual(arr.type		,					ArrayaDExtensionType((1, 3)		,					"int64"						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         with self.assertRaises((TypeError, pa.lib.ArrowInvalid)						):
           lowerCAmelCase					:					Optional[Any]								=							pa.array(TypedSequence(["foo", "bar"]		,					type=ArrayaD((1, 3)		,					"int64"						)						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							pa.array(TypedSequence([[[1, 2, 3]]]		,					try_type=ArrayaD((1, 3)		,					"int64"						)						)						)
         self.assertEqual(arr.type		,					ArrayaDExtensionType((1, 3)		,					"int64"						)						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							pa.array(TypedSequence(["foo", "bar"]		,					try_type=ArrayaD((1, 3)		,					"int64"						)						)						)
         self.assertEqual(arr.type		,					pa.string()						)







       @require_pil
       def 	lowercase__							(						self						):






         """simple docstring"""





         import PIL.Image

         lowerCAmelCase					:					Any								=							PIL.Image.fromarray(np.arange(10		,					dtype=np.uinta						).reshape(2		,					5						)						)
         with patch(
             "datasets.arrow_writer.cast_to_python_objects"		,					side_effect=snake_case__						) as mock_cast_to_python_objects:
           lowerCAmelCase					:					str								=							pa.array(TypedSequence([{"path": None, "bytes": B"image_bytes"}, pil_image]		,					type=Image()						)						)
           lowerCAmelCase						,  lowerCAmelCase					:					Tuple								=							mock_cast_to_python_objects.call_args_list[-1]
           self.assertIn("optimize_list_casting"		,					snake_case__						)
           self.assertFalse(kwargs["optimize_list_casting"]						)

def  a__      (    SCREAMING_SNAKE_CASE   :   Optional[int]    ,				SCREAMING_SNAKE_CASE   :   int    ):


  '''simple docstring'''







  lowerCAmelCase					:					List[str]								=							pa.BufferReader(SCREAMING_SNAKE_CASE    ) if isinstance(SCREAMING_SNAKE_CASE    ,				pa.Buffer    ) else pa.memory_map(SCREAMING_SNAKE_CASE    )
  lowerCAmelCase					:					Tuple								=							pa.ipc.open_stream(SCREAMING_SNAKE_CASE    )
  lowerCAmelCase					:					pa.Table								=							f.read_all()
  assert len(pa_table.to_batches()    ) == expected_num_chunks
  assert pa_table.to_pydict() == {"col_1": ["foo", "bar"], "col_2": [1, 2]}
  del pa_table
@pytest.mark.parametrize("writer_batch_size"    ,				[None, 1, 1_0]    )
@pytest.mark.parametrize(
    "fields"    ,				[None, {"col_1": pa.string(), "col_2": pa.intaa()}, {"col_1": pa.string(), "col_2": pa.intaa()}]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   int    ,				SCREAMING_SNAKE_CASE   :   str    ):


  '''simple docstring'''







  lowerCAmelCase					:					str								=							pa.BufferOutputStream()
  lowerCAmelCase					:					Tuple								=							pa.schema(SCREAMING_SNAKE_CASE    ) if fields else None
  with ArrowWriter(stream=SCREAMING_SNAKE_CASE    ,				schema=SCREAMING_SNAKE_CASE    ,				writer_batch_size=SCREAMING_SNAKE_CASE    ) as writer:
    writer.write({"col_1": "foo", "col_2": 1}    )
    writer.write({"col_1": "bar", "col_2": 2}    )
    lowerCAmelCase						,  lowerCAmelCase					:					Optional[Any]								=							writer.finalize()
  assert num_examples == 2
  assert num_bytes > 0
  if not fields:
    lowerCAmelCase					:					Union[str, Any]								=							{"col_1": pa.string(), "col_2": pa.intaa()}
  assert writer._schema == pa.schema(SCREAMING_SNAKE_CASE    ,				metadata=writer._schema.metadata    )
  _check_output(output.getvalue()    ,				expected_num_chunks=num_examples if writer_batch_size == 1 else 1    )
def  a__      (    ):


  '''simple docstring'''







  lowerCAmelCase					:					Optional[Any]								=							pa.BufferOutputStream()
  lowerCAmelCase					:					Any								=							Features({"labels": ClassLabel(names=["neg", "pos"]    )}    )
  with ArrowWriter(stream=SCREAMING_SNAKE_CASE    ,				features=SCREAMING_SNAKE_CASE    ) as writer:
    writer.write({"labels": 0}    )
    writer.write({"labels": 1}    )
    lowerCAmelCase						,  lowerCAmelCase					:					Dict								=							writer.finalize()
  assert num_examples == 2
  assert num_bytes > 0
  assert writer._schema == features.arrow_schema
  assert writer._schema.metadata == features.arrow_schema.metadata
  lowerCAmelCase					:					List[str]								=							pa.BufferReader(output.getvalue()    )
  lowerCAmelCase					:					str								=							pa.ipc.open_stream(SCREAMING_SNAKE_CASE    )
  lowerCAmelCase					:					pa.Table								=							f.read_all()
  lowerCAmelCase					:					Tuple								=							pa_table.schema
  assert pa_table.num_rows == 2
  assert schema == features.arrow_schema
  assert schema.metadata == features.arrow_schema.metadata
  assert features == Features.from_arrow_schema(SCREAMING_SNAKE_CASE    )
@pytest.mark.parametrize("writer_batch_size"    ,				[None, 1, 1_0]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   Optional[Any]    ):


  '''simple docstring'''







  lowerCAmelCase					:					Tuple								=							pa.BufferOutputStream()
  with ArrowWriter(
      stream=SCREAMING_SNAKE_CASE    ,				writer_batch_size=SCREAMING_SNAKE_CASE    ,				hash_salt="split_name"    ,				check_duplicates=SCREAMING_SNAKE_CASE    ,				) as writer:
    with pytest.raises(SCREAMING_SNAKE_CASE    ):
      writer.write({"col_1": "foo", "col_2": 1}    ,				key=[1, 2]    )
      lowerCAmelCase						,  lowerCAmelCase					:					List[str]								=							writer.finalize()
@pytest.mark.parametrize("writer_batch_size"    ,				[None, 2, 1_0]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   List[Any]    ):


  '''simple docstring'''







  lowerCAmelCase					:					Dict								=							pa.BufferOutputStream()
  with ArrowWriter(
      stream=SCREAMING_SNAKE_CASE    ,				writer_batch_size=SCREAMING_SNAKE_CASE    ,				hash_salt="split_name"    ,				check_duplicates=SCREAMING_SNAKE_CASE    ,				) as writer:
    with pytest.raises(SCREAMING_SNAKE_CASE    ):
      writer.write({"col_1": "foo", "col_2": 1}    ,				key=1_0    )
      writer.write({"col_1": "bar", "col_2": 2}    ,				key=1_0    )
      lowerCAmelCase						,  lowerCAmelCase					:					str								=							writer.finalize()
@pytest.mark.parametrize("writer_batch_size"    ,				[None, 2, 1_0]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   List[str]    ):


  '''simple docstring'''







  lowerCAmelCase					:					Optional[Any]								=							pa.BufferOutputStream()
  with ArrowWriter(
      stream=SCREAMING_SNAKE_CASE    ,				writer_batch_size=SCREAMING_SNAKE_CASE    ,				hash_salt="split_name"    ,				check_duplicates=SCREAMING_SNAKE_CASE    ,				) as writer:
    writer.write({"col_1": "foo", "col_2": 1}    ,				key=1    )
    writer.write({"col_1": "bar", "col_2": 2}    ,				key=2    )
    lowerCAmelCase						,  lowerCAmelCase					:					Optional[int]								=							writer.finalize()
  assert num_examples == 2
  assert num_bytes > 0
  _check_output(output.getvalue()    ,				expected_num_chunks=num_examples if writer_batch_size == 1 else 1    )
@pytest.mark.parametrize("writer_batch_size"    ,				[None, 1, 1_0]    )
@pytest.mark.parametrize(
    "fields"    ,				[None, {"col_1": pa.string(), "col_2": pa.intaa()}, {"col_1": pa.string(), "col_2": pa.intaa()}]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   Any    ,				SCREAMING_SNAKE_CASE   :   Union[str, Any]    ):


  '''simple docstring'''







  lowerCAmelCase					:					Optional[int]								=							pa.BufferOutputStream()
  lowerCAmelCase					:					Optional[int]								=							pa.schema(SCREAMING_SNAKE_CASE    ) if fields else None
  with ArrowWriter(stream=SCREAMING_SNAKE_CASE    ,				schema=SCREAMING_SNAKE_CASE    ,				writer_batch_size=SCREAMING_SNAKE_CASE    ) as writer:
    writer.write_batch({"col_1": ["foo", "bar"], "col_2": [1, 2]}    )
    writer.write_batch({"col_1": [], "col_2": []}    )
    lowerCAmelCase						,  lowerCAmelCase					:					List[Any]								=							writer.finalize()
  assert num_examples == 2
  assert num_bytes > 0
  if not fields:
    lowerCAmelCase					:					Dict								=							{"col_1": pa.string(), "col_2": pa.intaa()}
  assert writer._schema == pa.schema(SCREAMING_SNAKE_CASE    ,				metadata=writer._schema.metadata    )
  _check_output(output.getvalue()    ,				expected_num_chunks=num_examples if writer_batch_size == 1 else 1    )
@pytest.mark.parametrize("writer_batch_size"    ,				[None, 1, 1_0]    )
@pytest.mark.parametrize(
    "fields"    ,				[None, {"col_1": pa.string(), "col_2": pa.intaa()}, {"col_1": pa.string(), "col_2": pa.intaa()}]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   List[Any]    ,				SCREAMING_SNAKE_CASE   :   Optional[int]    ):


  '''simple docstring'''







  lowerCAmelCase					:					int								=							pa.BufferOutputStream()
  lowerCAmelCase					:					Union[str, Any]								=							pa.schema(SCREAMING_SNAKE_CASE    ) if fields else None
  with ArrowWriter(stream=SCREAMING_SNAKE_CASE    ,				schema=SCREAMING_SNAKE_CASE    ,				writer_batch_size=SCREAMING_SNAKE_CASE    ) as writer:
    writer.write_table(pa.Table.from_pydict({"col_1": ["foo", "bar"], "col_2": [1, 2]}    )    )
    lowerCAmelCase						,  lowerCAmelCase					:					str								=							writer.finalize()
  assert num_examples == 2
  assert num_bytes > 0
  if not fields:
    lowerCAmelCase					:					Tuple								=							{"col_1": pa.string(), "col_2": pa.intaa()}
  assert writer._schema == pa.schema(SCREAMING_SNAKE_CASE    ,				metadata=writer._schema.metadata    )
  _check_output(output.getvalue()    ,				expected_num_chunks=num_examples if writer_batch_size == 1 else 1    )
@pytest.mark.parametrize("writer_batch_size"    ,				[None, 1, 1_0]    )
@pytest.mark.parametrize(
    "fields"    ,				[None, {"col_1": pa.string(), "col_2": pa.intaa()}, {"col_1": pa.string(), "col_2": pa.intaa()}]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   Any    ,				SCREAMING_SNAKE_CASE   :   Optional[Any]    ):


  '''simple docstring'''







  lowerCAmelCase					:					Tuple								=							pa.BufferOutputStream()
  lowerCAmelCase					:					Dict								=							pa.schema(SCREAMING_SNAKE_CASE    ) if fields else None
  with ArrowWriter(stream=SCREAMING_SNAKE_CASE    ,				schema=SCREAMING_SNAKE_CASE    ,				writer_batch_size=SCREAMING_SNAKE_CASE    ) as writer:
    writer.write_row(pa.Table.from_pydict({"col_1": ["foo"], "col_2": [1]}    )    )
    writer.write_row(pa.Table.from_pydict({"col_1": ["bar"], "col_2": [2]}    )    )
    lowerCAmelCase						,  lowerCAmelCase					:					Dict								=							writer.finalize()
  assert num_examples == 2
  assert num_bytes > 0
  if not fields:
    lowerCAmelCase					:					int								=							{"col_1": pa.string(), "col_2": pa.intaa()}
  assert writer._schema == pa.schema(SCREAMING_SNAKE_CASE    ,				metadata=writer._schema.metadata    )
  _check_output(output.getvalue()    ,				expected_num_chunks=num_examples if writer_batch_size == 1 else 1    )
def  a__      (    ):


  '''simple docstring'''







  with tempfile.TemporaryDirectory() as tmp_dir:
    lowerCAmelCase					:					List[Any]								=							{"col_1": pa.string(), "col_2": pa.intaa()}
    lowerCAmelCase					:					List[str]								=							os.path.join(SCREAMING_SNAKE_CASE    ,				"test.arrow"    )
    with ArrowWriter(path=SCREAMING_SNAKE_CASE    ,				schema=pa.schema(SCREAMING_SNAKE_CASE    )    ) as writer:
      writer.write_batch({"col_1": ["foo", "bar"], "col_2": [1, 2]}    )
      lowerCAmelCase						,  lowerCAmelCase					:					Optional[Any]								=							writer.finalize()
    assert num_examples == 2
    assert num_bytes > 0
    assert writer._schema == pa.schema(SCREAMING_SNAKE_CASE    ,				metadata=writer._schema.metadata    )
    _check_output(SCREAMING_SNAKE_CASE    ,				1    )
def  a__      (    SCREAMING_SNAKE_CASE   :   List[Any]    ):


  '''simple docstring'''







  if pa.types.is_list(SCREAMING_SNAKE_CASE    ):
    return get_base_dtype(arr_type.value_type    )
  else:
    return arr_type
def  a__      (    SCREAMING_SNAKE_CASE   :   Optional[int]    ,				SCREAMING_SNAKE_CASE   :   List[Any]    ):


  '''simple docstring'''







  if isinstance(lst[0]    ,				SCREAMING_SNAKE_CASE    ):
    change_first_primitive_element_in_list(lst[0]    ,				SCREAMING_SNAKE_CASE    )
  else:
    lowerCAmelCase					:					Dict								=							value
@pytest.mark.parametrize("optimized_int_type, expected_dtype"    ,				[(None, pa.intaa()), (Value("int32"    ), pa.intaa())]    )
@pytest.mark.parametrize("sequence"    ,				[[1, 2, 3], [[1, 2, 3]], [[[1, 2, 3]]]]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   str    ,				SCREAMING_SNAKE_CASE   :   Optional[int]    ,				SCREAMING_SNAKE_CASE   :   str    ):


  '''simple docstring'''







  lowerCAmelCase					:					Union[str, Any]								=							pa.array(TypedSequence(SCREAMING_SNAKE_CASE    ,				optimized_int_type=SCREAMING_SNAKE_CASE    )    )
  assert get_base_dtype(arr.type    ) == expected_dtype
@pytest.mark.parametrize(
    "col, expected_dtype"    ,				[
        ("attention_mask", pa.inta()),
        ("special_tokens_mask", pa.inta()),
        ("token_type_ids", pa.inta()),
        ("input_ids", pa.intaa()),
        ("other", pa.intaa()),
    ]    ,				)
@pytest.mark.parametrize("sequence"    ,				[[1, 2, 3], [[1, 2, 3]], [[[1, 2, 3]]]]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   Optional[Any]    ,				SCREAMING_SNAKE_CASE   :   List[str]    ,				SCREAMING_SNAKE_CASE   :   List[str]    ):


  '''simple docstring'''







  lowerCAmelCase					:					Any								=							pa.array(OptimizedTypedSequence(SCREAMING_SNAKE_CASE    ,				col=SCREAMING_SNAKE_CASE    )    )
  assert get_base_dtype(arr.type    ) == expected_dtype

  # not in range
  if col != "other":
    # avoids errors due to in-place modifications
    lowerCAmelCase					:					int								=							copy.deepcopy(SCREAMING_SNAKE_CASE    )
    lowerCAmelCase					:					Optional[Any]								=							np.iinfo(expected_dtype.to_pandas_dtype()    ).max + 1
    change_first_primitive_element_in_list(SCREAMING_SNAKE_CASE    ,				SCREAMING_SNAKE_CASE    )
    lowerCAmelCase					:					Optional[Any]								=							pa.array(OptimizedTypedSequence(SCREAMING_SNAKE_CASE    ,				col=SCREAMING_SNAKE_CASE    )    )
    assert get_base_dtype(arr.type    ) == pa.intaa()
@pytest.mark.parametrize("raise_exception"    ,				[False, True]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   Tuple    ,				SCREAMING_SNAKE_CASE   :   List[str]    ):


  '''simple docstring'''







  lowerCAmelCase					:					List[str]								=							str(tmp_path / "dataset-train.arrow"    )
  try:
    with ArrowWriter(path=SCREAMING_SNAKE_CASE    ) as writer:
      if raise_exception:
        raise pa.lib.ArrowInvalid()
      else:
        writer.stream.close()
  except pa.lib.ArrowInvalid:
    pass
  finally:
    assert writer.stream.closed
def  a__      (    SCREAMING_SNAKE_CASE   :   Dict    ):


  '''simple docstring'''







  lowerCAmelCase					:					str								=							"mock://dataset-train.arrow"
  with ArrowWriter(path=SCREAMING_SNAKE_CASE    ,				storage_options=mockfs.storage_options    ) as writer:
    assert isinstance(writer._fs    ,				type(SCREAMING_SNAKE_CASE    )    )
    assert writer._fs.storage_options == mockfs.storage_options
    writer.write({"col_1": "foo", "col_2": 1}    )
    writer.write({"col_1": "bar", "col_2": 2}    )
    lowerCAmelCase						,  lowerCAmelCase					:					Any								=							writer.finalize()
  assert num_examples == 2
  assert num_bytes > 0
  assert mockfs.exists(SCREAMING_SNAKE_CASE    )
def  a__      (    ):


  '''simple docstring'''







  lowerCAmelCase					:					List[str]								=							pa.BufferOutputStream()
  with ParquetWriter(stream=SCREAMING_SNAKE_CASE    ) as writer:
    writer.write({"col_1": "foo", "col_2": 1}    )
    writer.write({"col_1": "bar", "col_2": 2}    )
    lowerCAmelCase						,  lowerCAmelCase					:					Optional[Any]								=							writer.finalize()
  assert num_examples == 2
  assert num_bytes > 0
  lowerCAmelCase					:					Dict								=							pa.BufferReader(output.getvalue()    )
  lowerCAmelCase					:					pa.Table								=							pq.read_table(SCREAMING_SNAKE_CASE    )
  assert pa_table.to_pydict() == {"col_1": ["foo", "bar"], "col_2": [1, 2]}
@require_pil
@pytest.mark.parametrize("embed_local_files"    ,				[False, True]    )
def  a__      (    SCREAMING_SNAKE_CASE   :   Any    ,				SCREAMING_SNAKE_CASE   :   Optional[Any]    ):


  '''simple docstring'''







  import PIL.Image

  lowerCAmelCase					:					Optional[int]								=							str(tmp_path / "test_image_rgb.jpg"    )
  PIL.Image.fromarray(np.zeros((5, 5)    ,				dtype=np.uinta    )    ).save(SCREAMING_SNAKE_CASE    ,				format="png"    )
  lowerCAmelCase					:					List[str]								=							pa.BufferOutputStream()
  with ParquetWriter(
      stream=SCREAMING_SNAKE_CASE    ,				features=Features({"image": Image()}    )    ,				embed_local_files=SCREAMING_SNAKE_CASE    ) as writer:
    writer.write({"image": image_path}    )
    writer.finalize()
  lowerCAmelCase					:					List[Any]								=							pa.BufferReader(output.getvalue()    )
  lowerCAmelCase					:					pa.Table								=							pq.read_table(SCREAMING_SNAKE_CASE    )
  lowerCAmelCase					:					Optional[Any]								=							pa_table.to_pydict()
  if embed_local_files:
    assert isinstance(out["image"][0]["path"]    ,				SCREAMING_SNAKE_CASE    )
    with open(SCREAMING_SNAKE_CASE    ,				"rb"    ) as f:
      assert out["image"][0]["bytes"] == f.read()
  else:
    assert out["image"][0]["path"] == image_path
    assert out["image"][0]["bytes"] is None





def  a__      (    ):


  '''simple docstring'''







  lowerCAmelCase					:					Dict								=							pa.schema([pa.field("col_1"    ,				pa.string()    ,				nullable=SCREAMING_SNAKE_CASE    )]    )
  lowerCAmelCase					:					Dict								=							pa.BufferOutputStream()
  with ArrowWriter(stream=SCREAMING_SNAKE_CASE    ) as writer:
    writer._build_writer(inferred_schema=SCREAMING_SNAKE_CASE    )
    assert writer._schema == pa.schema([pa.field("col_1"    ,				pa.string()    )]    )









"""simple docstring"""







from typing import Any


class 				SCREAMING_SNAKE_CASE__    :
       """simple docstring"""


       def __init__(						self		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							data
         lowerCAmelCase					:					Tuple								=							None


class 				SCREAMING_SNAKE_CASE__    :
       """simple docstring"""


       def __init__(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[int]								=							None

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							self.head
         while temp is not None:
           print(temp.data		,					end=" "						)
           lowerCAmelCase					:					List[str]								=							temp.next
         print()

       def 	lowercase__							(						self		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					int								=							Node(snake_case__						)
         lowerCAmelCase					:					Union[str, Any]								=							self.head
         lowerCAmelCase					:					Optional[Any]								=							new_node







       def 	lowercase__							(						self		,					snake_case__		,					snake_case__						):






         """simple docstring"""





         if node_data_a == node_data_a:
           return
         else:
           lowerCAmelCase					:					str								=							self.head
           while node_a is not None and node_a.data != node_data_a:
             lowerCAmelCase					:					Union[str, Any]								=							node_a.next

           lowerCAmelCase					:					Any								=							self.head
           while node_a is not None and node_a.data != node_data_a:
             lowerCAmelCase					:					List[Any]								=							node_a.next

           if node_a is None or node_a is None:
             return

           lowerCAmelCase						,  lowerCAmelCase					:					str								=							node_a.data, node_a.data


if __name__ == "__main__":
     lowerCAmelCase__				    =       LinkedList()
     for i in range(5, 0, -1):
          ll.push(i)

     ll.print_list()

     ll.swap_nodes(1, 4)
     print('''After swapping''')
     ll.print_list()





