code: def test_pandas_categorical_roundtrip():
      # ARROW-5480, this was enabled by ARROW-3246
  
      # Have one of the categories unobserved and include a null (-1)
      codes = np.array([2, 0, 0, 2, 0, -1, 2], dtype="int32")
      categories = ["foo", "bar", "baz"]
      df = pd.DataFrame(
          {"x": pd.Categorical.from_codes(codes, categories=categories)}
      )
  
      buf = pa.BufferOutputStream()
      pq.write_table(pa.table(df), buf)
  
      result = pq.read_table(buf.getvalue()).to_pandas()
      assert result.x.dtype == "category"
      assert (result.x.cat.categories == categories).all()
      tm.assert_frame_equal(result, df)
  
imports: import io
  import json
  import numpy
  import pytest
  import pyarrow
  from pyarrow.fs import LocalFileSystem, SubTreeFileSystem
  from pyarrow.util import guid
  from pyarrow.vendored.version import Version
label_desc: Use image node_id 21 for calling a global function with example usage: test_pandas_categorical_roundtrip() without return types