code: def _create_possibly_ragged_ndarray(
      values: Union[np.ndarray, "ABCSeries", Sequence[Any]]
  ) -> np.ndarray:
      """
      Create a possibly ragged ndarray.
      Using the np.array() constructor will fail to construct a ragged ndarray that has a
      uniform first dimension (e.g. uniform channel dimension in imagery). This function
      catches this failure and tries a create-and-fill method to construct the ragged
      ndarray.
      """
      try:
          with warnings.catch_warnings():
              # For NumPy < 1.24, constructing a ragged ndarray directly via
              # `np.array(...)` without the `dtype=object` parameter will raise a
              # VisibleDeprecationWarning which we suppress.
              # More details: https://stackoverflow.com/q/63097829
              warnings.simplefilter(
                  "ignore", category=np.VisibleDeprecationWarning
              )
              return np.array(values, copy=False)
      except ValueError as e:
          # Constructing a ragged ndarray directly via `np.array(...)`
          # without the `dtype=object` parameter will raise a ValueError.
          # For NumPy < 1.24, the message is of the form:
          # "could not broadcast input array from shape..."
          # For NumPy >= 1.24, the message is of the form:
          # "The requested array has an inhomogeneous shape..."
          # More details: https://github.com/numpy/numpy/pull/22004
          error_str = str(e)
          if (
              "could not broadcast input array from shape" in error_str
              or "The requested array has an inhomogeneous shape"
              in error_str
          ):
              # Fall back to strictly creating a ragged ndarray.
              return create_ragged_ndarray(values)
          else:
              # Re-raise original error if the failure wasn't a broadcast error.
              raise e from None
  
imports: from typing import Any, Sequence, Union, TYPE_CHECKING
  import warnings
  import numpy
  from ray.util import PublicAPI
label_desc: Use image node_id 2 for calling a global function with example usage: _create_possibly_ragged_ndarray(values) and returns: np, create_ragged_ndarray