code: def test_categories_with_string_pyarrow_dtype(tempdir):
      # gh-33727: writing to parquet should not fail
      if Version(pd.__version__) < Version("1.3.0"):
          pytest.skip(
              "PyArrow backed string data type introduced in pandas 1.3.0"
          )
  
      df1 = pd.DataFrame(
          {"x": ["foo", "bar", "foo"]}, dtype="string[pyarrow]"
      )
      df1 = df1.astype("category")
  
      df2 = pd.DataFrame({"x": ["foo", "bar", "foo"]})
      df2 = df2.astype("category")
  
      # categories should be converted to pa.Array
      assert (
          pa.array(df1["x"]).to_pylist()
          == pa.array(df2["x"]).to_pylist()
      )
      assert (
          pa.array(df1["x"].cat.categories.values).to_pylist()
          == pa.array(df2["x"].cat.categories.values).to_pylist()
      )
  
      path = str(tempdir / "cat.parquet")
      pq.write_table(pa.table(df1), path)
      result = pq.read_table(path).to_pandas()
  
      tm.assert_frame_equal(result, df2)
  
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 22 for calling a global function with example usage: test_categories_with_string_pyarrow_dtype(tempdir) without return types