class_docstr: This data container generalizes the typing when instantiating pyarrow arrays, tables or batches.
  
  More specifically it adds several features:
  - Support extension types like ``datasets.features.Array2DExtensionType``:
      By default pyarrow arrays don't return extension arrays. One has to call
      ``pa.ExtensionArray.from_storage(type, pa.array(data, type.storage_type))``
      in order to get an extension array.
  - Support for ``try_type`` parameter that can be used instead of ``type``:
      When an array is transformed, we like to keep the same type as before if possible.
      For example when calling :func:`datasets.Dataset.map`, we don't want to change the type
      of each column by default.
  - Better error message when a pyarrow array overflows.
  
  Example::
  
      from datasets.features import Array2D, Array2DExtensionType, Value
      from datasets.arrow_writer import TypedSequence
      import pyarrow as pa
  
      arr = pa.array(TypedSequence([1, 2, 3], type=Value("int32")))
      assert arr.type == pa.int32()
  
      arr = pa.array(TypedSequence([1, 2, 3], try_type=Value("int32")))
      assert arr.type == pa.int32()
  
      arr = pa.array(TypedSequence(["foo", "bar"], try_type=Value("int32")))
      assert arr.type == pa.string()
  
      arr = pa.array(TypedSequence([[[1, 2, 3]]], type=Array2D((1, 3), "int64")))
      assert arr.type == Array2DExtensionType((1, 3), "int64")
  
      table = pa.Table.from_pydict({
          "image": TypedSequence([[[1, 2, 3]]], type=Array2D((1, 3), "int64"))
      })
      assert table["image"].type == Array2DExtensionType((1, 3), "int64")
class_docstr_tok: ["This","data","container","generalizes","the","typing","when","instantiating","pyarrow","arrays",",","tables","or","batches",".","More","specifically","it","adds","several","features",":","-","Support","extension","types","like","``","datasets.features.Array2DExtensionType","``",":","By","default","pyarrow","arrays","do","n't","return","extension","arrays",".","One","has","to","call","``","pa.ExtensionArray.from_storage","(","type",",","pa.array","(","data",",","type.storage_type",")",")","``","in","order","to","get","an","extension","array",".","-","Support","for","``","try_type","``","parameter","that","can","be","used","instead","of","``","type","``",":","When","an","array","is","transformed",",","we","like","to","keep","the","same","type","as","before","if","possible",".","For","example","when","calling",":","func",":","`","datasets.Dataset.map","`",",","we","do","n't","want","to","change","the","type","of","each","column","by","default",".","-","Better","error","message","when","a","pyarrow","array","overflows",".","Example",":",":","from","datasets.features","import","Array2D",",","Array2DExtensionType",",","Value","from","datasets.arrow_writer","import","TypedSequence","import","pyarrow","as","pa","arr","=","pa.array","(","TypedSequence","(","[","1",",","2",",","3","]",",","type=Value","(","``","int32","''",")",")",")","assert","arr.type","==","pa.int32","(",")","arr","=","pa.array","(","TypedSequence","(","[","1",",","2",",","3","]",",","try_type=Value","(","``","int32","''",")",")",")","assert","arr.type","==","pa.int32","(",")","arr","=","pa.array","(","TypedSequence","(","[","``","foo","''",",","``","bar","''","]",",","try_type=Value","(","``","int32","''",")",")",")","assert","arr.type","==","pa.string","(",")","arr","=","pa.array","(","TypedSequence","(","[","[","[","1",",","2",",","3","]","]","]",",","type=Array2D","(","(","1",",","3",")",",","``","int64","''",")",")",")","assert","arr.type","==","Array2DExtensionType","(","(","1",",","3",")",",","``","int64","''",")","table","=","pa.Table.from_pydict","(","{","``","image","''",":","TypedSequence","(","[","[","[","1",",","2",",","3","]","]","]",",","type=Array2D","(","(","1",",","3",")",",","``","int64","''",")",")","}",")","assert","table","[","``","image","''","]",".type","==","Array2DExtensionType","(","(","1",",","3",")",",","``","int64","''",")"]
code: def __init__(
      self,
      data: Iterable,
      type: Optional[FeatureType] = None,
      try_type: Optional[FeatureType] = None,
      optimized_int_type: Optional[FeatureType] = None,
  ):
      # assert type is None or try_type is None,
      if type is not None and try_type is not None:
          raise ValueError("You cannot specify both type and try_type")
      # set attributes
      self.data = data
      self.type = type
      self.try_type = (
          try_type  # is ignored if it doesn't match the data
      )
      self.optimized_int_type = optimized_int_type
      # when trying a type (is ignored if data is not compatible)
      self.trying_type = self.try_type is not None
      self.trying_int_optimization = (
          optimized_int_type is not None
          and type is None
          and try_type is None
      )
      # used to get back the inferred type after __arrow_array__() is called once
      self._inferred_type = None
  
imports: import errno
  import json
  import os
  import sys
  from pathlib import Path
  from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
  import fsspec
  import numpy
  import pyarrow
  import pyarrow.parquet
  from .None import config
  from .features import Features, Image, Value
  from .features.features import FeatureType, _ArrayXDExtensionType, cast_to_python_objects, generate_from_arrow_type, get_nested_type, list_of_np_array_to_pyarrow_listarray, numpy_to_pyarrow_listarray, to_pyarrow_listarray
  from .filesystems import is_remote_filesystem
  from .info import DatasetInfo
  from .keyhash import DuplicatedKeysError, KeyHasher
  from .table import array_cast, array_concat, cast_array_to_feature, embed_table_storage, table_cast
  from .utils import logging
  from .utils import tqdm
  from .utils.file_utils import hash_url_to_filename
  from .utils.py_utils import asdict, first_non_null_value
label_desc: Use image node_id 1 to create a new TypedSequence object  with example: obj = TypedSequence(data, type, try_type, optimized_int_type)