code: def expect_stages(pipe, num_stages_expected, stage_names):
      stats = pipe.stats()
      for name in stage_names:
          name = " " + name + ":"
          assert name in stats, (name, stats)
      if isinstance(pipe, Dataset):
          pass
      else:
          assert (
              len(pipe._optimized_stages) == num_stages_expected
          ), pipe._optimized_stages
  
imports: import os
  from typing import List
  import numpy
  import pandas
  import pytest
  import ray
  from ray._private.internal_api import memory_summary
  from ray.data import Dataset
  from ray.data.block import BlockMetadata
  from ray.data.context import DataContext
  from ray.data.datasource import Datasource, ReadTask
  from ray.data.datasource.csv_datasource import CSVDatasource
  from ray.data.tests.util import column_udf, extract_values
  from ray.tests.conftest import *
label_desc: Use image node_id 1 for calling a global function with example usage: expect_stages(pipe, num_stages_expected, stage_names) without return types