code: def test_sort_arrow_with_empty_blocks(
      ray_start_regular, use_push_based_shuffle, use_polars
  ):
      ctx = ray.data.context.DataContext.get_current()
  
      try:
          original_use_polars = ctx.use_polars
          ctx.use_polars = use_polars
  
          assert (
              BlockAccessor.for_block(pa.Table.from_pydict({}))
              .sample(10, SortKey("A"))
              .num_rows
              == 0
          )
  
          partitions = BlockAccessor.for_block(
              pa.Table.from_pydict({})
          ).sort_and_partition([1, 5, 10], SortKey("A"))
          assert len(partitions) == 4
          for partition in partitions:
              assert partition.num_rows == 0
  
          assert (
              BlockAccessor.for_block(pa.Table.from_pydict({}))
              .merge_sorted_blocks(
                  [pa.Table.from_pydict({})], SortKey("A")
              )[0]
              .num_rows
              == 0
          )
  
          ds = ray.data.from_items(
              [{"A": (x % 3), "B": x} for x in range(3)], parallelism=3
          )
          ds = ds.filter(lambda r: r["A"] == 0)
          assert list(ds.sort("A").iter_rows()) == [{"A": 0, "B": 0}]
  
          # Test empty dataset.
          ds = ray.data.range(10).filter(lambda r: r["id"] > 10)
          assert (
              len(
                  ray.data._internal.sort.sample_boundaries(
                      ds._plan.execute().get_blocks(), SortKey("id"), 3
                  )
              )
              == 2
          )
          assert ds.sort("id").count() == 0
      finally:
          ctx.use_polars = original_use_polars
  
imports: import random
  from collections import defaultdict
  import numpy
  import pandas
  import pyarrow
  import pytest
  import ray
  from ray.data import Dataset
  from ray.data._internal.planner.exchange.push_based_shuffle_task_scheduler import PushBasedShuffleTaskScheduler
  from ray.data._internal.sort import SortKey
  from ray.data.block import BlockAccessor
  from ray.data.context import DataContext
  from ray.data.tests.conftest import *
  from ray.data.tests.util import extract_values
  from ray.tests.conftest import *
label_desc: Use image node_id 5 for calling a global function with example usage: test_sort_arrow_with_empty_blocks(ray_start_regular, use_push_based_shuffle, use_polars) without return types