code: def _cast_tensor_columns_to_ndarrays(
      df: "pd.DataFrame",
  ) -> "pd.DataFrame":
      """Cast all tensor extension columns in df to NumPy ndarrays."""
      pd = _lazy_import_pandas()
      try:
          SettingWithCopyWarning = pd.core.common.SettingWithCopyWarning
      except AttributeError:
          # SettingWithCopyWarning was moved to pd.errors in Pandas 1.5.0.
          SettingWithCopyWarning = pd.errors.SettingWithCopyWarning
      from ray.air.util.tensor_extensions.pandas import TensorDtype
  
      # Try to convert any tensor extension columns to ndarray columns.
      # TODO(Clark): Optimize this with propagated DataFrame metadata containing a list of
      # column names containing tensor columns, to make this an O(# of tensor columns)
      # check rather than the current O(# of columns) check.
      for col_name, col in df.items():
          if isinstance(col.dtype, TensorDtype):
              # Suppress Pandas warnings:
              # https://github.com/ray-project/ray/issues/29270
              # We actually want in-place operations so we surpress this warning.
              # https://stackoverflow.com/a/74193599
              with warnings.catch_warnings():
                  warnings.simplefilter(
                      "ignore", category=FutureWarning
                  )
                  warnings.simplefilter(
                      "ignore", category=SettingWithCopyWarning
                  )
                  df.loc[:, col_name] = pd.Series(list(col.to_numpy()))
      return df
  
imports: from enum import Enum
  from typing import Dict, Union, List, TYPE_CHECKING
  import warnings
  import numpy
  from ray.air.data_batch_type import DataBatchType
  from ray.air.constants import TENSOR_COLUMN_NAME
  from ray.util.annotations import Deprecated, DeveloperAPI
label_desc: Use image node_id 10 for calling a global function with example usage: _cast_tensor_columns_to_ndarrays(df) and returns: df