code: def astype(df, dtype, copy=True, errors="raise"):
      """
      Cast a pandas object to a specified dtype ``dtype``.
  
      Parameters
      ----------
      dtype : data type, or dict of column name -> data type
          Use a numpy.dtype or Python type to cast entire pandas object to
          the same type. Alternatively, use {col: dtype, ...}, where col is a
          column label and dtype is a numpy.dtype or Python type to cast one
          or more of the DataFrame's columns to column-specific types.
      copy : bool, default True
          Return a copy when ``copy=True`` (be very careful setting
          ``copy=False`` as changes to values then may propagate to other
          pandas objects).
      errors : {'raise', 'ignore'}, default 'raise'
          Control raising of exceptions on invalid data for provided dtype.
  
          - ``raise`` : allow exceptions to be raised
          - ``ignore`` : suppress exceptions. On error return original object.
  
      Returns
      -------
      casted : same type as caller
  
      See Also
      --------
      to_datetime : Convert argument to datetime.
      to_timedelta : Convert argument to timedelta.
      to_numeric : Convert argument to a numeric type.
      numpy.ndarray.astype : Cast a numpy array to a specified type.
  
      Examples
      --------
      Create a DataFrame:
  
      >>> import mars.dataframe as md
      >>> df = md.DataFrame(pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}))
      >>> df.dtypes
      col1    int64
      col2    int64
      dtype: object
  
      Cast all columns to int32:
  
      >>> df.astype('int32').dtypes
      col1    int32
      col2    int32
      dtype: object
  
      Cast col1 to int32 using a dictionary:
  
      >>> df.astype({'col1': 'int32'}).dtypes
      col1    int32
      col2    int64
      dtype: object
  
      Create a series:
  
      >>> ser = md.Series(pd.Series([1, 2], dtype='int32'))
      >>> ser.execute()
      0    1
      1    2
      dtype: int32
      >>> ser.astype('int64').execute()
      0    1
      1    2
      dtype: int64
  
      Convert to categorical type:
  
      >>> ser.astype('category').execute()
      0    1
      1    2
      dtype: category
      Categories (2, int64): [1, 2]
  
      Convert to ordered categorical type with custom ordering:
  
      >>> cat_dtype = pd.api.types.CategoricalDtype(
      ...     categories=[2, 1], ordered=True)
      >>> ser.astype(cat_dtype).execute()
      0    1
      1    2
      dtype: category
      Categories (2, int64): [2 < 1]
  
      Note that using ``copy=False`` and changing data on a new
      pandas object may propagate changes:
  
      >>> s1 = md.Series(pd.Series([1, 2]))
      >>> s2 = s1.astype('int64', copy=False)
      >>> s1.execute()  # note that s1[0] has changed too
      0     1
      1     2
      dtype: int64
      """
      if isinstance(dtype, dict):
          keys = list(dtype.keys())
          if isinstance(df, SERIES_TYPE):
              if len(keys) != 1 or keys[0] != df.name:
                  raise KeyError(
                      "Only the Series name can be used for the key in Series dtype mappings."
                  )
              else:
                  dtype = list(dtype.values())[0]
          else:
              for k in keys:
                  columns = df.columns_value.to_pandas()
                  if k not in columns:
                      raise KeyError(
                          "Only a column name can be used for the key in a dtype mappings argument."
                      )
      op = DataFrameAstype(dtype_values=dtype, errors=errors)
      r = op(df)
      if not copy:
          df.data = r.data
          return df
      else:
          return r
  
imports: import numpy
  import pandas
  from pandas.api.types import CategoricalDtype
  from ...None import opcodes
  from ...core import recursive_tile
  from ...serialization.serializables import AnyField, StringField, ListField
  from ...tensor.base import sort
  from ...utils import pd_release_version
  from ..core import DATAFRAME_TYPE, SERIES_TYPE
  from ..operands import DataFrameOperand, DataFrameOperandMixin
  from ..utils import build_empty_df, build_empty_series, parse_index
label_desc: Use image node_id 1 for calling a global function with example usage: astype(df, dtype, copy, errors) and returns: df, r