class_docstr: Provides accessor methods for a specific block.
  
  Ideally, we wouldn't need a separate accessor classes for blocks. However,
  this is needed if we want to support storing ``pyarrow.Table`` directly
  as a top-level Ray object, without a wrapping class (issue #17186).
class_docstr_tok: ["Provides","accessor","methods","for","a","specific","block",".","Ideally",",","we","would","n't","need","a","separate","accessor","classes","for","blocks",".","However",",","this","is","needed","if","we","want","to","support","storing","``","pyarrow.Table","``","directly","as","a","top-level","Ray","object",",","without","a","wrapping","class","(","issue","#","17186",")","."]
docstr: Create a block from user-facing data formats.
docstr_tok: ["Create","a","block","from","user-facing","data","formats","."]
code: def batch_to_block(batch: DataBatch) -> Block:
      """Create a block from user-facing data formats."""
  
      if isinstance(batch, np.ndarray):
          raise ValueError(
              f"Error validating {_truncated_repr(batch)}: "
              "Standalone numpy arrays are not "
              "allowed in Ray 2.5. Return a dict of field -> array, "
              "e.g., `{'data': array}` instead of `array`."
          )
  
      elif isinstance(batch, collections.abc.Mapping):
          import pyarrow as pa
  
          from ray.data._internal.arrow_block import ArrowBlockAccessor
  
          try:
              return ArrowBlockAccessor.numpy_to_block(batch)
          except (
              pa.ArrowNotImplementedError,
              pa.ArrowInvalid,
              pa.ArrowTypeError,
          ):
              import pandas as pd
  
              # TODO(ekl) once we support Python objects within Arrow blocks, we
              # don't need this fallback path.
              return pd.DataFrame(dict(batch))
      return batch
  
imports: import collections
  import os
  import time
  from dataclasses import dataclass
  from typing import TYPE_CHECKING, Callable, Dict, Iterator, List, Literal, Optional, Protocol, Tuple, TypeVar, Union
  import numpy
  import ray
  from ray import DynamicObjectRefGenerator
  from ray.data._internal.util import _check_pyarrow_version, _truncated_repr
  from ray.types import ObjectRef
  from ray.util.annotations import DeveloperAPI
  import psutil
label_desc: Use image node_id 18 for calling the BlockAccessor obj's underlying member method code with example usage: obj.batch_to_block(batch) and returns: batch, ArrowBlockAccessor, pd