code: def test_astype(setup):
      rs = np.random.RandomState(0)
      raw = pd.DataFrame(
          rs.randint(1000, size=(20, 8)),
          columns=["c" + str(i + 1) for i in range(8)],
      )
      # single chunk
      df = from_pandas_df(raw)
      r = df.astype("int32")
  
      result = r.execute().fetch()
      expected = raw.astype("int32")
      pd.testing.assert_frame_equal(expected, result)
  
      # multiply chunks
      df = from_pandas_df(raw, chunk_size=6)
      r = df.astype("int32")
  
      result = r.execute().fetch()
      expected = raw.astype("int32")
      pd.testing.assert_frame_equal(expected, result)
  
      # dict type
      df = from_pandas_df(raw, chunk_size=5)
      r = df.astype({"c1": "int32", "c2": "float", "c8": "str"})
  
      result = r.execute().fetch()
      expected = raw.astype({"c1": "int32", "c2": "float", "c8": "str"})
      pd.testing.assert_frame_equal(expected, result)
  
      # test arrow_string dtype
      df = from_pandas_df(raw, chunk_size=8)
      r = df.astype({"c1": "arrow_string"})
  
      result = r.execute().fetch()
      expected = raw.astype({"c1": "arrow_string"})
      pd.testing.assert_frame_equal(expected, result)
  
      # test series
      s = pd.Series(rs.randint(5, size=20))
      series = from_pandas_series(s)
      r = series.astype("int32")
  
      result = r.execute().fetch()
      expected = s.astype("int32")
      pd.testing.assert_series_equal(result, expected)
  
      series = from_pandas_series(s, chunk_size=6)
      r = series.astype("arrow_string")
  
      result = r.execute().fetch()
      expected = s.astype("arrow_string")
      pd.testing.assert_series_equal(result, expected)
  
      # test index
      raw = pd.Index(rs.randint(5, size=20))
      mix = from_pandas_index(raw)
      r = mix.astype("int32")
  
      result = r.execute().fetch()
      expected = raw.astype("int32")
      pd.testing.assert_index_equal(result, expected)
  
      # multiply chunks
      series = from_pandas_series(s, chunk_size=6)
      r = series.astype("str")
  
      result = r.execute().fetch()
      expected = s.astype("str")
      pd.testing.assert_series_equal(result, expected)
  
      # test category
      raw = pd.DataFrame(
          rs.randint(3, size=(20, 8)),
          columns=["c" + str(i + 1) for i in range(8)],
      )
  
      df = from_pandas_df(raw)
      r = df.astype("category")
  
      result = r.execute().fetch()
      expected = raw.astype("category")
      pd.testing.assert_frame_equal(expected, result)
  
      df = from_pandas_df(raw)
      r = df.astype({"c1": "category", "c8": "int32", "c4": "str"})
  
      result = r.execute().fetch()
      expected = raw.astype(
          {"c1": "category", "c8": "int32", "c4": "str"}
      )
      pd.testing.assert_frame_equal(expected, result)
  
      df = from_pandas_df(raw, chunk_size=5)
      r = df.astype("category")
  
      result = r.execute().fetch()
      expected = raw.astype("category")
      pd.testing.assert_frame_equal(expected, result)
  
      df = from_pandas_df(raw, chunk_size=3)
      r = df.astype({"c1": "category", "c8": "int32", "c4": "str"})
  
      result = r.execute().fetch()
      expected = raw.astype(
          {"c1": "category", "c8": "int32", "c4": "str"}
      )
      pd.testing.assert_frame_equal(expected, result)
  
      df = from_pandas_df(raw, chunk_size=6)
      r = df.astype(
          {
              "c1": "category",
              "c5": "float",
              "c2": "int32",
              "c7": pd.CategoricalDtype([1, 3, 4, 2]),
              "c4": pd.CategoricalDtype([1, 3, 2]),
          }
      )
      result = r.execute().fetch()
      expected = raw.astype(
          {
              "c1": "category",
              "c5": "float",
              "c2": "int32",
              "c7": pd.CategoricalDtype([1, 3, 4, 2]),
              "c4": pd.CategoricalDtype([1, 3, 2]),
          }
      )
      pd.testing.assert_frame_equal(expected, result)
  
      df = from_pandas_df(raw, chunk_size=8)
      r = df.astype({"c2": "category"})
      result = r.execute().fetch()
      expected = raw.astype({"c2": "category"})
      pd.testing.assert_frame_equal(expected, result)
  
      # test series category
      raw = pd.Series(np.random.choice(["a", "b", "c"], size=(10,)))
      series = from_pandas_series(raw, chunk_size=4)
      result = series.astype("category").execute().fetch()
      expected = raw.astype("category")
      pd.testing.assert_series_equal(expected, result)
  
      series = from_pandas_series(raw, chunk_size=3)
      result = (
          series.astype(
              pd.CategoricalDtype(["a", "c", "b"]), copy=False
          )
          .execute()
          .fetch()
      )
      expected = raw.astype(
          pd.CategoricalDtype(["a", "c", "b"]), copy=False
      )
      pd.testing.assert_series_equal(expected, result)
  
      series = from_pandas_series(raw, chunk_size=6)
      result = (
          series.astype(pd.CategoricalDtype(["a", "c", "b", "d"]))
          .execute()
          .fetch()
      )
      expected = raw.astype(pd.CategoricalDtype(["a", "c", "b", "d"]))
      pd.testing.assert_series_equal(expected, result)
  
imports: import random
  from collections import OrderedDict
  import numpy
  import pandas
  import pytest
  import mars
  from ....config import options, option_context
  from ....dataframe import DataFrame, Series
  from ....tensor import arange, tensor
  from ....tensor.random import rand
  from ....tests.core import require_cudf
  from ....utils import lazy_import, pd_release_version, no_default
  from ...None import eval, cut, qcut, get_dummies
  from ...core import DATAFRAME_OR_SERIES_TYPE
  from ...datasource.dataframe import from_pandas
  from ...datasource.series import from_pandas
  from ...datasource.index import from_pandas
  from ..None import to_gpu, to_cpu
  from ..bloom_filter import filter_by_bloom_filter
  from ..shift import _enable_no_default, _with_column_freq_bug
  from ..to_numeric import to_numeric
  from ..rebalance import DataFrameRebalance
label_desc: Use image node_id 25 for calling a global function with example usage: test_astype(setup) without return types