code: def safe_cast(values, dtype, copy):
      """
      Safely cast the values to the dtype if they
      are equivalent, meaning floats must be equivalent to the
      ints.
  
      """
  
      try:
          return values.astype(dtype, casting="safe", copy=copy)
      except TypeError:
          casted = values.astype(dtype, copy=copy)
          if (casted == values).all():
              return casted
  
          raise TypeError(
              "cannot safely cast non-equivalent {} to {}".format(
                  values.dtype, np.dtype(dtype)
              )
          )
  
imports: import copy
  import sys
  import warnings
  import numpy
  from pandas._libs import lib
  from pandas.compat import range, set_function_name, string_types
  from pandas.util._decorators import cache_readonly
  from pandas.core.dtypes.base import ExtensionDtype
  from pandas.core.dtypes.cast import astype_nansafe
  from pandas.core.dtypes.common import is_bool_dtype, is_float, is_float_dtype, is_integer, is_integer_dtype, is_list_like, is_object_dtype, is_scalar
  from pandas.core.dtypes.dtypes import register_extension_dtype
  from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
  from pandas.core.dtypes.missing import isna, notna
  from pandas.core import nanops
  from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin
  from pandas.core.tools.numeric import to_numeric
label_desc: Use image node_id 2 for calling a global function with example usage: safe_cast(values, dtype, copy) and returns: values, casted