class_docstr: An ExtensionDtype to hold a single size & kind of integer dtype.
  
  These specific implementations are subclasses of the non-public
  IntegerDtype. For example, we have Int8Dtype to represent signed int 8s.
  
  The attributes name & type are set when these subclasses are created.
class_docstr_tok: ["An","ExtensionDtype","to","hold","a","single","size","&","kind","of","integer","dtype",".","These","specific","implementations","are","subclasses","of","the","non-public","IntegerDtype",".","For","example",",","we","have","Int8Dtype","to","represent","signed","int","8s",".","The","attributes","name","&","type","are","set","when","these","subclasses","are","created","."]
docstr: Safely cast the values to the given dtype.
  
  "safe" in this context means the casting is lossless. e.g. if 'values'
  has a floating dtype, each value must be an integer.
docstr_tok: ["Safely","cast","the","values","to","the","given","dtype",".","``","safe","''","in","this","context","means","the","casting","is","lossless",".","e.g",".","if","'values'","has","a","floating","dtype",",","each","value","must","be","an","integer","."]
code: def _safe_cast(
      cls, values: np.ndarray, dtype: np.dtype, copy: bool
  ) -> np.ndarray:
      """
      Safely cast the values to the given dtype.
  
      "safe" in this context means the casting is lossless. e.g. if 'values'
      has a floating dtype, each value must be an integer.
      """
      try:
          return values.astype(dtype, casting="safe", copy=copy)
      except TypeError as err:
          casted = values.astype(dtype, copy=copy)
          if (casted == values).all():
              return casted
  
          raise TypeError(
              f"cannot safely cast non-equivalent {values.dtype} to {np.dtype(dtype)}"
          ) from err
  
imports: from __future__ import annotations
  import numpy
  from pandas.core.dtypes.base import register_extension_dtype
  from pandas.core.dtypes.common import is_integer_dtype
  from pandas.core.arrays.numeric import NumericArray, NumericDtype
label_desc: Use image node_id 3 for calling the IntegerDtype obj's underlying member method code with example usage: obj._safe_cast(cls, values, dtype, copy) and returns: values, casted