code: def test_replace_categorical(
      to_replace, value, result, expected_error_msg
  ):
      # GH#26988
      cat = Categorical(["a", "b"])
      expected = Categorical(result)
      msg = (
          r"The behavior of Series\.replace \(and DataFrame.replace\) "
          "with CategoricalDtype"
      )
      warn = FutureWarning if expected_error_msg is not None else None
      with tm.assert_produces_warning(warn, match=msg):
          result = (
              pd.Series(cat, copy=False)
              .replace(to_replace, value)
              ._values
          )
  
      tm.assert_categorical_equal(result, expected)
      if to_replace == "b":  # the "c" test is supposed to be unchanged
          with pytest.raises(AssertionError, match=expected_error_msg):
              # ensure non-inplace call does not affect original
              tm.assert_categorical_equal(cat, expected)
  
      ser = pd.Series(cat, copy=False)
      with tm.assert_produces_warning(warn, match=msg):
          ser.replace(to_replace, value, inplace=True)
      tm.assert_categorical_equal(cat, expected)
  
file_path: pandas/pandas/tests/arrays/categorical/test_replace.py
imports: import pytest
  import pandas
  from pandas import Categorical
  import pandas._testing
label_desc: Use image node_id 2 for calling a global function with example usage: test_replace_categorical(to_replace, value, result, expected_error_msg) without return types