code: def _export_import_batch_reader(ptr_stream, reader_factory):
      # Prepare input
      batches = make_batches()
      schema = batches[0].schema
  
      reader = reader_factory(schema, batches)
      reader._export_to_c(ptr_stream)
      # Delete and recreate C++ object from exported pointer
      del reader, batches
  
      reader_new = pa.RecordBatchReader._import_from_c(ptr_stream)
      assert reader_new.schema == schema
      got_batches = list(reader_new)
      del reader_new
      assert got_batches == make_batches()
  
      # Test read_pandas()
      if pd is not None:
          batches = make_batches()
          schema = batches[0].schema
          expected_df = pa.Table.from_batches(batches).to_pandas()
  
          reader = reader_factory(schema, batches)
          reader._export_to_c(ptr_stream)
          del reader, batches
  
          reader_new = pa.RecordBatchReader._import_from_c(ptr_stream)
          got_df = reader_new.read_pandas()
          del reader_new
          tm.assert_frame_equal(expected_df, got_df)
  
imports: import contextlib
  import ctypes
  import gc
  import pyarrow
  import pytest
label_desc: Use image node_id 20 for calling a global function with example usage: _export_import_batch_reader(ptr_stream, reader_factory) without return types