code: def astype_array(
      values: ArrayLike, dtype: DtypeObj, copy: bool = False
  ) -> ArrayLike:
      """
      Cast array (ndarray or ExtensionArray) to the new dtype.
  
      Parameters
      ----------
      values : ndarray or ExtensionArray
      dtype : dtype object
      copy : bool, default False
          copy if indicated
  
      Returns
      -------
      ndarray or ExtensionArray
      """
      if is_dtype_equal(values.dtype, dtype):
          if copy:
              return values.copy()
          return values
  
      if not isinstance(values, np.ndarray):
          # i.e. ExtensionArray
          values = values.astype(dtype, copy=copy)
  
      else:
          values = _astype_nansafe(values, dtype, copy=copy)
  
      # in pandas we don't store numpy str dtypes, so convert to object
      if isinstance(dtype, np.dtype) and issubclass(
          values.dtype.type, str
      ):
          values = np.array(values, dtype=object)
  
      return values
  
file_path: catboost/contrib/python/pandas/py3/pandas/core/dtypes/astype.py
imports: from __future__ import annotations
  import inspect
  from typing import TYPE_CHECKING, overload
  import warnings
  import numpy
  from pandas._libs import lib
  from pandas._libs.tslibs.timedeltas import array_to_timedelta64
  from pandas._typing import ArrayLike, DtypeObj, IgnoreRaise
  from pandas.errors import IntCastingNaNError
  from pandas.core.dtypes.common import is_datetime64_dtype, is_dtype_equal, is_integer_dtype, is_object_dtype, is_string_dtype, is_timedelta64_dtype, pandas_dtype
  from pandas.core.dtypes.dtypes import ExtensionDtype, PandasDtype
label_desc: Use image node_id 5 for calling a global function with example usage: astype_array(values, dtype, copy) and returns: values, values, values