class_docstr: Image [`Feature`] to read image data from an image file.
  
  Input: The Image feature accepts as input:
  - A `str`: Absolute path to the image file (i.e. random access is allowed).
  - A `dict` with the keys:
  
      - `path`: String with relative path of the image file to the archive file.
      - `bytes`: Bytes of the image file.
  
    This is useful for archived files with sequential access.
  
  - An `np.ndarray`: NumPy array representing an image.
  - A `PIL.Image.Image`: PIL image object.
  
  Args:
      decode (`bool`, defaults to `True`):
          Whether to decode the image data. If `False`,
          returns the underlying dictionary in the format `{"path": image_path, "bytes": image_bytes}`.
  
  Examples:
  
  ```py
  >>> from datasets import load_dataset, Image
  >>> ds = load_dataset("beans", split="train")
  >>> ds.features["image"]
  Image(decode=True, id=None)
  >>> ds[0]["image"]
  <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=500x500 at 0x15E52E7F0>
  >>> ds = ds.cast_column('image', Image(decode=False))
  {'bytes': None,
   'path': '/root/.cache/huggingface/datasets/downloads/extracted/b0a21163f78769a2cf11f58dfc767fb458fc7cea5c05dccc0144a2c0f0bc1292/train/healthy/healthy_train.85.jpg'}
  ```
class_docstr_tok: ["Image","[","`","Feature","`","]","to","read","image","data","from","an","image","file",".","Input",":","The","Image","feature","accepts","as","input",":","-","A","`","str","`",":","Absolute","path","to","the","image","file","(","i.e",".","random","access","is","allowed",")",".","-","A","`","dict","`","with","the","keys",":","-","`","path","`",":","String","with","relative","path","of","the","image","file","to","the","archive","file",".","-","`","bytes","`",":","Bytes","of","the","image","file",".","This","is","useful","for","archived","files","with","sequential","access",".","-","An","`","np.ndarray","`",":","NumPy","array","representing","an","image",".","-","A","`","PIL.Image.Image","`",":","PIL","image","object",".","Args",":","decode","(","`","bool","`",",","defaults","to","`","True","`",")",":","Whether","to","decode","the","image","data",".","If","`","False","`",",","returns","the","underlying","dictionary","in","the","format","`","{","``","path","''",":","image_path",",","``","bytes","''",":","image_bytes","}","`",".","Examples",":","``","`","py",">",">",">","from","datasets","import","load_dataset",",","Image",">",">",">","ds","=","load_dataset","(","``","beans","''",",","split=","''","train","''",")",">",">",">","ds.features","[","``","image","''","]","Image","(","decode=True",",","id=None",")",">",">",">","ds","[","0","]","[","``","image","''","]","<","PIL.JpegImagePlugin.JpegImageFile","image","mode=RGB","size=500x500","at","0x15E52E7F0",">",">",">",">","ds","=","ds.cast_column","(","'image","'",",","Image","(","decode=False",")",")","{","'bytes","'",":","None",",","'path","'",":","'\/root\/.cache\/huggingface\/datasets\/downloads\/extracted\/b0a21163f78769a2cf11f58dfc767fb458fc7cea5c05dccc0144a2c0f0bc1292\/train\/healthy\/healthy_train.85.jpg","'","}","``","`"]
docstr: Cast an Arrow array to the Image arrow storage type.
  The Arrow types that can be converted to the Image pyarrow storage type are:
  
  - `pa.string()` - it must contain the "path" data
  - `pa.binary()` - it must contain the image bytes
  - `pa.struct({"bytes": pa.binary()})`
  - `pa.struct({"path": pa.string()})`
  - `pa.struct({"bytes": pa.binary(), "path": pa.string()})`  - order doesn't matter
  - `pa.list(*)` - it must contain the image array data
  
  Args:
      storage (`Union[pa.StringArray, pa.StructArray, pa.ListArray]`):
          PyArrow array to cast.
  
  Returns:
      `pa.StructArray`: Array in the Image arrow storage type, that is
          `pa.struct({"bytes": pa.binary(), "path": pa.string()})`.
docstr_tok: ["Cast","an","Arrow","array","to","the","Image","arrow","storage","type",".","The","Arrow","types","that","can","be","converted","to","the","Image","pyarrow","storage","type","are",":","-","`","pa.string","(",")","`","-","it","must","contain","the","``","path","''","data","-","`","pa.binary","(",")","`","-","it","must","contain","the","image","bytes","-","`","pa.struct","(","{","``","bytes","''",":","pa.binary","(",")","}",")","`","-","`","pa.struct","(","{","``","path","''",":","pa.string","(",")","}",")","`","-","`","pa.struct","(","{","``","bytes","''",":","pa.binary","(",")",",","``","path","''",":","pa.string","(",")","}",")","`","-","order","does","n't","matter","-","`","pa.list","(","*",")","`","-","it","must","contain","the","image","array","data","Args",":","storage","(","`","Union","[","pa.StringArray",",","pa.StructArray",",","pa.ListArray","]","`",")",":","PyArrow","array","to","cast",".","Returns",":","`","pa.StructArray","`",":","Array","in","the","Image","arrow","storage","type",",","that","is","`","pa.struct","(","{","``","bytes","''",":","pa.binary","(",")",",","``","path","''",":","pa.string","(",")","}",")","`","."]
code: def cast_storage(
      self, storage: Union[pa.StringArray, pa.StructArray, pa.ListArray]
  ) -> pa.StructArray:
      """Cast an Arrow array to the Image arrow storage type.
      The Arrow types that can be converted to the Image pyarrow storage type are:
  
      - `pa.string()` - it must contain the "path" data
      - `pa.binary()` - it must contain the image bytes
      - `pa.struct({"bytes": pa.binary()})`
      - `pa.struct({"path": pa.string()})`
      - `pa.struct({"bytes": pa.binary(), "path": pa.string()})`  - order doesn't matter
      - `pa.list(*)` - it must contain the image array data
  
      Args:
          storage (`Union[pa.StringArray, pa.StructArray, pa.ListArray]`):
              PyArrow array to cast.
  
      Returns:
          `pa.StructArray`: Array in the Image arrow storage type, that is
              `pa.struct({"bytes": pa.binary(), "path": pa.string()})`.
      """
      if pa.types.is_string(storage.type):
          bytes_array = pa.array(
              [None] * len(storage), type=pa.binary()
          )
          storage = pa.StructArray.from_arrays(
              [bytes_array, storage],
              ["bytes", "path"],
              mask=storage.is_null(),
          )
      elif pa.types.is_binary(storage.type):
          path_array = pa.array([None] * len(storage), type=pa.string())
          storage = pa.StructArray.from_arrays(
              [storage, path_array],
              ["bytes", "path"],
              mask=storage.is_null(),
          )
      elif pa.types.is_struct(storage.type):
          if storage.type.get_field_index("bytes") >= 0:
              bytes_array = storage.field("bytes")
          else:
              bytes_array = pa.array(
                  [None] * len(storage), type=pa.binary()
              )
          if storage.type.get_field_index("path") >= 0:
              path_array = storage.field("path")
          else:
              path_array = pa.array(
                  [None] * len(storage), type=pa.string()
              )
          storage = pa.StructArray.from_arrays(
              [bytes_array, path_array],
              ["bytes", "path"],
              mask=storage.is_null(),
          )
      elif pa.types.is_list(storage.type):
          bytes_array = pa.array(
              [
                  encode_np_array(np.array(arr))["bytes"]
                  if arr is not None
                  else None
                  for arr in storage.to_pylist()
              ],
              type=pa.binary(),
          )
          path_array = pa.array([None] * len(storage), type=pa.string())
          storage = pa.StructArray.from_arrays(
              [bytes_array, path_array],
              ["bytes", "path"],
              mask=bytes_array.is_null(),
          )
      return array_cast(storage, self.pa_type)
  
imports: import os
  import sys
  import warnings
  from dataclasses import dataclass, field
  from io import BytesIO
  from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union
  import numpy
  import pyarrow
  from ..None import config
  from ..download.download_config import DownloadConfig
  from ..download.streaming_download_manager import xopen
  from ..table import array_cast
  from ..utils.file_utils import is_local_path
  from ..utils.py_utils import first_non_null_value, no_op_if_value_is_null, string_to_dict
label_desc: Use image node_id 5 for calling the Image obj's underlying member method code with example usage: obj.cast_storage(storage) and returns: array_cast