code: def _to_ndarray_helper(shape, value_type, offset, data_buffer):
      if pa.types.is_boolean(value_type):
          # Arrow boolean array buffers are bit-packed, with 8 entries per byte,
          # and are accessed via bit offsets.
          buffer_item_width = value_type.bit_width
      else:
          # We assume all other array types are accessed via byte array
          # offsets.
          buffer_item_width = value_type.bit_width // 8
      data_offset = buffer_item_width * offset
  
      if pa.types.is_boolean(value_type):
          # Special handling for boolean arrays, since Arrow
          # bit-packs boolean arrays while NumPy does not.
          # Cast as uint8 array and let NumPy unpack into a boolean view.
          # Offset into uint8 array, where each element is
          # a bucket for 8 booleans.
          byte_bucket_offset = data_offset // 8
          # Offset for a specific boolean, within a uint8 array element.
          bool_offset = data_offset % 8
          # The number of uint8 array elements (buckets) that our slice spans.
          # Note that, due to the offset for a specific boolean,
          # the slice can span byte boundaries even if it contains
          # less than 8 booleans.
          num_boolean_byte_buckets = 1 + (
              (bool_offset + np.prod(shape) - 1) // 8
          )
          # Construct the uint8 array view on the buffer.
          arr = np.ndarray(
              (num_boolean_byte_buckets,),
              dtype=np.uint8,
              buffer=data_buffer,
              offset=byte_bucket_offset,
          )
          # Unpack into a byte per boolean, using LSB bit-packed ordering.
          arr = np.unpackbits(arr, bitorder="little")
          # Interpret buffer as boolean array.
          return np.ndarray(
              shape, dtype=np.bool_, buffer=arr, offset=bool_offset
          )
      ext_dtype = value_type.to_pandas_dtype()
      # Special handling of ragged string tensors
      if pa.types.is_fixed_size_binary(value_type):
          ext_dtype = np.dtype(
              f"<U{value_type.byte_width // NUM_BYTES_PER_UNICODE_CHAR}"
          )
      return np.ndarray(
          shape, dtype=ext_dtype, buffer=data_buffer, offset=data_offset
      )
  
imports: import itertools
  import json
  import sys
  from typing import Iterable, Optional, Tuple, List, Sequence, Union
  from packaging.version import parse
  import numpy
  import pyarrow
  from ray.air.util.tensor_extensions.utils import _is_ndarray_variable_shaped_tensor, create_ragged_ndarray
  from ray._private.utils import _get_pyarrow_version
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 6 for calling a global function with example usage: _to_ndarray_helper(shape, value_type, offset, data_buffer) and returns: np, np