code: def test_sort_values_execution(setup, distinct_opt):
      ns = np.random.RandomState(0)
      os.environ["PSRS_DISTINCT_COL"] = distinct_opt
      df = pd.DataFrame(
          ns.rand(100, 10), columns=["a" + str(i) for i in range(10)]
      )
  
      # test one chunk
      mdf = DataFrame(df)
      result = mdf.sort_values("a0").execute().fetch()
      expected = df.sort_values("a0")
  
      pd.testing.assert_frame_equal(result, expected)
  
      result = (
          mdf.sort_values(["a6", "a7"], ascending=False)
          .execute()
          .fetch()
      )
      expected = df.sort_values(["a6", "a7"], ascending=False)
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test psrs
      mdf = DataFrame(df, chunk_size=10)
      result = mdf.sort_values("a0").execute().fetch()
      expected = df.sort_values("a0")
  
      pd.testing.assert_frame_equal(result, expected)
  
      result = mdf.sort_values(["a3", "a4"]).execute().fetch()
      expected = df.sort_values(["a3", "a4"])
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test ascending=False
      result = (
          mdf.sort_values(["a0", "a1"], ascending=False)
          .execute()
          .fetch()
      )
      expected = df.sort_values(["a0", "a1"], ascending=False)
  
      pd.testing.assert_frame_equal(result, expected)
  
      result = (
          mdf.sort_values(["a7"], ascending=False).execute().fetch()
      )
      expected = df.sort_values(["a7"], ascending=False)
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test ascending is a list
      result = (
          mdf.sort_values(
              ["a3", "a4", "a5", "a6"],
              ascending=[False, True, True, False],
          )
          .execute()
          .fetch()
      )
      expected = df.sort_values(
          ["a3", "a4", "a5", "a6"], ascending=[False, True, True, False]
      )
      pd.testing.assert_frame_equal(result, expected)
  
      in_df = pd.DataFrame(
          {
              "col1": ns.choice(
                  [f"a{i}" for i in range(5)], size=(100,)
              ),
              "col2": ns.choice(
                  [f"b{i}" for i in range(5)], size=(100,)
              ),
              "col3": ns.choice(
                  [f"c{i}" for i in range(5)], size=(100,)
              ),
              "col4": ns.randint(10, 20, size=(100,)),
          }
      )
      mdf = DataFrame(in_df, chunk_size=10)
      result = (
          mdf.sort_values(
              ["col1", "col4", "col3", "col2"],
              ascending=[False, False, True, False],
          )
          .execute()
          .fetch()
      )
      expected = in_df.sort_values(
          ["col1", "col4", "col3", "col2"],
          ascending=[False, False, True, False],
      )
      pd.testing.assert_frame_equal(result, expected)
  
      # test multiindex
      df2 = df.copy(deep=True)
      df2.columns = pd.MultiIndex.from_product(
          [list("AB"), list("CDEFG")]
      )
      mdf = DataFrame(df2, chunk_size=5)
  
      result = mdf.sort_values([("A", "C")]).execute().fetch()
      expected = df2.sort_values([("A", "C")])
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test rechunk
      mdf = DataFrame(df, chunk_size=3)
      result = mdf.sort_values("a0").execute().fetch()
      expected = df.sort_values("a0")
  
      pd.testing.assert_frame_equal(result, expected)
  
      result = mdf.sort_values(["a3", "a4"]).execute().fetch()
      expected = df.sort_values(["a3", "a4"])
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test other types
      raw = pd.DataFrame(
          {
              "a": np.random.rand(10),
              "b": np.random.randint(1000, size=10),
              "c": np.random.rand(10),
              "d": [np.random.bytes(10) for _ in range(10)],
              "e": [pd.Timestamp(f"201{i}") for i in range(10)],
              "f": [pd.Timedelta(f"{i} days") for i in range(10)],
          },
      )
      mdf = DataFrame(raw, chunk_size=3)
  
      for label in raw.columns:
          result = mdf.sort_values(label).execute().fetch()
          expected = raw.sort_values(label)
          pd.testing.assert_frame_equal(result, expected)
  
      result = (
          mdf.sort_values(["a", "b", "e"], ascending=False)
          .execute()
          .fetch()
      )
      expected = raw.sort_values(["a", "b", "e"], ascending=False)
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test nan
      df = pd.DataFrame(
          {
              "col1": ["A", "A", "B", "B", "D", "C"],
              "col2": [2, 1, 9, np.nan, 7, 4],
              "col3": [0, 1, 9, 4, 2, 3],
          }
      )
      mdf = DataFrame(df)
      result = mdf.sort_values(["col2"]).execute().fetch()
      expected = df.sort_values(["col2"])
  
      pd.testing.assert_frame_equal(result, expected)
  
      mdf = DataFrame(df, chunk_size=3)
      result = mdf.sort_values(["col2"]).execute().fetch()
      expected = df.sort_values(["col2"])
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test None (issue #1885)
      df = pd.DataFrame(np.random.rand(1000, 10))
  
      df[0][df[0] < 0.5] = "A"
      df[0][df[0] != "A"] = None
  
      mdf = DataFrame(df)
      result = mdf.sort_values([0, 1]).execute().fetch()
      expected = df.sort_values([0, 1])
  
      pd.testing.assert_frame_equal(result, expected)
  
      mdf = DataFrame(df, chunk_size=100)
      result = mdf.sort_values([0, 1]).execute().fetch()
      expected = df.sort_values([0, 1])
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test ignore_index
      df = pd.DataFrame(
          np.random.rand(10, 3),
          columns=["a" + str(i) for i in range(3)],
      )
  
      mdf = DataFrame(df, chunk_size=3)
      result = (
          mdf.sort_values(["a0", "a1"], ignore_index=True)
          .execute()
          .fetch()
      )
      try:  # for python3.5
          expected = df.sort_values(["a0", "a1"], ignore_index=True)
      except TypeError:
          expected = df.sort_values(["a0", "a1"])
          expected.index = pd.RangeIndex(len(expected))
  
      pd.testing.assert_frame_equal(result, expected)
  
      # test inplace
      mdf = DataFrame(df)
      mdf.sort_values("a0", inplace=True)
      result = mdf.execute().fetch()
      df.sort_values("a0", inplace=True)
  
      pd.testing.assert_frame_equal(result, df)
  
      # test unknown shape
      df = pd.DataFrame(
          {"a": list(range(10)), "b": np.random.random(10)}
      )
      mdf = DataFrame(df, chunk_size=4)
      filtered = mdf[mdf["a"] > 2]
      result = filtered.sort_values(by="b").execute().fetch()
  
      pd.testing.assert_frame_equal(
          result, df[df["a"] > 2].sort_values(by="b")
      )
  
      # test empty dataframe
      df = pd.DataFrame(
          {"a": list(range(10)), "b": np.random.random(10)}
      )
      mdf = DataFrame(df, chunk_size=4)
      filtered = mdf[mdf["b"] > 100]
      result = filtered.sort_values(by="b").execute().fetch()
  
      pd.testing.assert_frame_equal(
          result, df[df["b"] > 100].sort_values(by="b")
      )
  
      # test chunks with zero length
      df = pd.DataFrame(
          {"a": list(range(10)), "b": np.random.random(10)}
      )
      df.iloc[4:8, 1] = 0
  
      mdf = DataFrame(df, chunk_size=4)
      filtered = mdf[mdf["b"] != 0]
      result = filtered.sort_values(by="b").execute().fetch()
  
      pd.testing.assert_frame_equal(
          result, df[df["b"] != 0].sort_values(by="b")
      )
  
      # test Series.sort_values
      raw = pd.Series(np.random.rand(10))
      series = Series(raw)
      result = series.sort_values().execute().fetch()
      expected = raw.sort_values()
  
      pd.testing.assert_series_equal(result, expected)
  
      series = Series(raw, chunk_size=3)
      result = series.sort_values().execute().fetch()
      expected = raw.sort_values()
  
      pd.testing.assert_series_equal(result, expected)
  
      series = Series(raw, chunk_size=2)
      result = series.sort_values(ascending=False).execute().fetch()
      expected = raw.sort_values(ascending=False)
  
      pd.testing.assert_series_equal(result, expected)
  
      # test empty series
      series = pd.Series(list(range(10)), name="a")
      mseries = Series(series, chunk_size=4)
      filtered = mseries[mseries > 100]
      result = filtered.sort_values().execute().fetch()
  
      pd.testing.assert_series_equal(
          result, series[series > 100].sort_values()
      )
  
      # test series with None
      series = pd.Series(np.arange(1000))
  
      series[series < 500] = "A"
      series[series != "A"] = None
  
      mseries = Series(series, chunk_size=100)
      result = mseries.sort_values().execute().fetch()
      expected = series.sort_values()
      pd.testing.assert_series_equal(
          result.reset_index(drop=True), expected.reset_index(drop=True)
      )
  
      # test for empty input(#GH 2649)
      pd_df = pd.DataFrame(
          np.random.rand(10, 3), columns=["col1", "col2", "col3"]
      )
      df = DataFrame(pd_df, chunk_size=4)
      df = df[df["col2"] > 1].execute()
      result = df.sort_values(by="col1").execute().fetch()
      expected = pd_df[pd_df["col2"] > 1].sort_values(by="col1")
      pd.testing.assert_frame_equal(result, expected)
  
      pd_s = pd.Series(np.random.rand(10))
      s = Series(pd_s, chunk_size=4)
      s = s[s > 1].execute()
      result = s.sort_values().execute().fetch()
      expected = pd_s[pd_s > 1].sort_values()
      pd.testing.assert_series_equal(result, expected)
  
file_path: mars/mars/dataframe/sort/tests/test_sort_execution.py
imports: import os
  import sys
  import numpy
  import pandas
  import pytest
  from ....tests.core import require_cudf
  from ...None import DataFrame, Series, ArrowStringDtype
label_desc: Use image node_id 1 for calling a global function with example usage: test_sort_values_execution(setup, distinct_opt) without return types